diff --git a/ElunaEventMgr.cpp b/ElunaEventMgr.cpp index fe364b7..6e045ac 100644 --- a/ElunaEventMgr.cpp +++ b/ElunaEventMgr.cpp @@ -108,7 +108,8 @@ void ElunaEventProcessor::AddEvent(int funcRef, uint32 delay, uint32 repeats) 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 luaL_unref((*E)->L, LUA_REGISTRYINDEX, luaEvent->funcRef); diff --git a/LuaEngine.h b/LuaEngine.h index 98371f2..5604938 100644 --- a/LuaEngine.h +++ b/LuaEngine.h @@ -269,8 +269,9 @@ public: } void RunScripts(); - bool GetReload() const { return reload; } + bool ShouldReload() const { return reload; } 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); // Non-static pushes, to be used in hooks. diff --git a/ServerHooks.cpp b/ServerHooks.cpp index d4717c5..5ea59ee 100644 --- a/ServerHooks.cpp +++ b/ServerHooks.cpp @@ -376,7 +376,7 @@ void Eluna::OnWorldUpdate(uint32 diff) { { LOCK_ELUNA; - if (reload) + if (ShouldReload()) _ReloadEluna(); }