Skip to content

Commit 5c8c894

Browse files
Synchronize changes from 1.6 master branch [ci skip]
c3a1ddf Fix cross-resource timer access (#827) (#4422)
2 parents 36671ff + c3a1ddf commit 5c8c894

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

Server/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,11 @@ CXMLNode* UserDataCast(CXMLNode* ptr, lua_State* luaState)
316316
//
317317
CLuaTimer* UserDataCast(CLuaTimer* ptr, lua_State* luaState)
318318
{
319-
if (CLuaMain* luaMain = g_pGame->GetLuaManager()->GetVirtualMachine(luaState); luaMain != nullptr)
320-
{
321-
return luaMain->GetTimerManager()->GetTimerFromScriptID(reinterpret_cast<unsigned long>(ptr));
322-
}
323-
324-
return nullptr;
319+
CLuaManager* luaManager = g_pGame->GetLuaManager();
320+
if (!luaManager)
321+
return nullptr;
322+
323+
return luaManager->FindTimerGlobally(reinterpret_cast<unsigned long>(ptr));
325324
}
326325

327326
//

Server/mods/deathmatch/logic/lua/CLuaManager.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "luadefs/CLuaVoiceDefs.h"
4444
#include "luadefs/CLuaWorldDefs.h"
4545
#include "luadefs/CLuaCompatibilityDefs.h"
46+
#include "CIdArray.h"
4647

4748
extern CGame* g_pGame;
4849

@@ -184,6 +185,35 @@ CResource* CLuaManager::GetVirtualMachineResource(lua_State* luaVM)
184185
return NULL;
185186
}
186187

188+
CLuaTimer* CLuaManager::FindTimerGlobally(unsigned long scriptID) const
189+
{
190+
// First check if timer exists in global ID system
191+
CLuaTimer* luaTimer = static_cast<CLuaTimer*>(CIdArray::FindEntry(scriptID, EIdClass::TIMER));
192+
if (!luaTimer)
193+
return nullptr;
194+
195+
// Verify timer exists in any resource manager (ensures it's still valid)
196+
for (std::list<CLuaMain*>::const_iterator iter = m_virtualMachines.begin(); iter != m_virtualMachines.end(); ++iter)
197+
{
198+
CLuaMain* luaMain = *iter;
199+
if (!luaMain)
200+
continue;
201+
202+
CLuaTimerManager* timerManager = luaMain->GetTimerManager();
203+
if (!timerManager)
204+
continue;
205+
206+
if (timerManager->GetTimerFromScriptID(scriptID) == luaTimer)
207+
{
208+
return luaTimer;
209+
}
210+
}
211+
212+
// Timer exists in global ID array but not in any resource manager
213+
// This indicates the timer has been cleaned up
214+
return nullptr;
215+
}
216+
187217
void CLuaManager::LoadCFunctions()
188218
{
189219
// Load the functions from our classes

Server/mods/deathmatch/logic/lua/CLuaManager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class CLuaManager;
2222
// Predeclarations
2323
class CBlipManager;
2424
class CEvents;
25+
class CLuaTimer;
2526
class CMapManager;
2627
class CObjectManager;
2728
class CPlayerManager;
@@ -52,6 +53,8 @@ class CLuaManager
5253

5354
void LoadCFunctions();
5455

56+
CLuaTimer* FindTimerGlobally(unsigned long scriptID) const;
57+
5558
private:
5659
CBlipManager* m_pBlipManager;
5760
CObjectManager* m_pObjectManager;

0 commit comments

Comments
 (0)