Fix shutdown crash

This commit is contained in:
Rochet2
2015-03-12 18:54:06 +02:00
parent 9452beae3d
commit a2955a3081
3 changed files with 5 additions and 3 deletions

View File

@@ -108,7 +108,8 @@ void ElunaEventProcessor::AddEvent(int funcRef, uint32 delay, uint32 repeats)
void ElunaEventProcessor::RemoveEvent(LuaEvent* luaEvent) void ElunaEventProcessor::RemoveEvent(LuaEvent* luaEvent)
{ {
if (luaEvent->state != LUAEVENT_STATE_ERASE && Eluna::IsInitialized()) // Unreference if should and if Eluna was not yet uninitialized and if the lua state still exists
if (luaEvent->state != LUAEVENT_STATE_ERASE && Eluna::IsInitialized() && (*E)->HasLuaState())
{ {
// Free lua function ref // Free lua function ref
luaL_unref((*E)->L, LUA_REGISTRYINDEX, luaEvent->funcRef); luaL_unref((*E)->L, LUA_REGISTRYINDEX, luaEvent->funcRef);

View File

@@ -269,8 +269,9 @@ public:
} }
void RunScripts(); void RunScripts();
bool GetReload() const { return reload; } bool ShouldReload() const { return reload; }
bool IsEnabled() const { return enabled && IsInitialized(); } bool IsEnabled() const { return enabled && IsInitialized(); }
bool HasLuaState() const { return L; }
void Register(uint8 reg, uint32 id, uint64 guid, uint32 instanceId, uint32 evt, int func, uint32 shots); void Register(uint8 reg, uint32 id, uint64 guid, uint32 instanceId, uint32 evt, int func, uint32 shots);
// Non-static pushes, to be used in hooks. // Non-static pushes, to be used in hooks.

View File

@@ -376,7 +376,7 @@ void Eluna::OnWorldUpdate(uint32 diff)
{ {
{ {
LOCK_ELUNA; LOCK_ELUNA;
if (reload) if (ShouldReload())
_ReloadEluna(); _ReloadEluna();
} }