LuaState: Fixed untracking references.
One thread may untrack a ref while another thread was closing the LuaState, which had emptied the tracked refs.
This commit is contained in:
parent
e28cecb3d1
commit
e9547101b1
@ -2288,15 +2288,17 @@ void cLuaState::UntrackRef(cTrackedRef & a_Ref)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the callback:
|
// Remove the callback (note that another thread may have cleared the callbacks by closing the LuaState):
|
||||||
cCSLock Lock(canonState->m_CSTrackedRefs);
|
cCSLock Lock(canonState->m_CSTrackedRefs);
|
||||||
auto & trackedRefs = canonState->m_TrackedRefs;
|
auto & trackedRefs = canonState->m_TrackedRefs;
|
||||||
trackedRefs.erase(std::remove_if(trackedRefs.begin(), trackedRefs.end(),
|
for (auto itr = trackedRefs.begin(), end = trackedRefs.end(); itr != end; ++itr)
|
||||||
[&a_Ref](cTrackedRef * a_StoredRef)
|
|
||||||
{
|
{
|
||||||
return (a_StoredRef == &a_Ref);
|
if (*itr == &a_Ref)
|
||||||
|
{
|
||||||
|
trackedRefs.erase(itr);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -522,7 +522,8 @@ public:
|
|||||||
/** Allows this object to be used in the same way as a lua_State *, for example in the LuaLib functions */
|
/** Allows this object to be used in the same way as a lua_State *, for example in the LuaLib functions */
|
||||||
operator lua_State * (void) { return m_LuaState; }
|
operator lua_State * (void) { return m_LuaState; }
|
||||||
|
|
||||||
/** Creates the m_LuaState, if not closed already. This state will be automatically closed in the destructor.
|
/** Creates the m_LuaState, if not created already.
|
||||||
|
This state will be automatically closed in the destructor.
|
||||||
The regular Lua libs are registered, but the MCS API is not registered (so that Lua can be used as
|
The regular Lua libs are registered, but the MCS API is not registered (so that Lua can be used as
|
||||||
lite-config as well), use RegisterAPILibs() to do that. */
|
lite-config as well), use RegisterAPILibs() to do that. */
|
||||||
void Create(void);
|
void Create(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user