From 75a28a149bbb35ad88ffb3feec0ee756ad93b3a9 Mon Sep 17 00:00:00 2001 From: kervala Date: Fri, 13 Nov 2015 19:18:41 +0100 Subject: [PATCH] Fixed: Crash in CLuaManager --- code/nel/include/nel/gui/lua_manager.h | 6 +++++- code/nel/src/gui/lua_manager.cpp | 19 ++++++++++++++++--- code/ryzom/client/src/release.cpp | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/code/nel/include/nel/gui/lua_manager.h b/code/nel/include/nel/gui/lua_manager.h index 00aecbe84..01c123f55 100644 --- a/code/nel/include/nel/gui/lua_manager.h +++ b/code/nel/include/nel/gui/lua_manager.h @@ -31,8 +31,8 @@ namespace NLGUI class CLuaManager { public: - ~CLuaManager(); + /// Get or create singleton static CLuaManager& getInstance() { if( instance == NULL ) @@ -42,6 +42,9 @@ namespace NLGUI return *instance; } + /// Release singleton + static void releaseInstance(); + /// Enables attaching the Lua debugger in the CLuaState instance, only matters on startup. static void enableLuaDebugging(){ debugLua = true; } @@ -65,6 +68,7 @@ namespace NLGUI private: CLuaManager(); + ~CLuaManager(); static CLuaManager *instance; static bool debugLua; diff --git a/code/nel/src/gui/lua_manager.cpp b/code/nel/src/gui/lua_manager.cpp index 95e6767f1..2b354b0e4 100644 --- a/code/nel/src/gui/lua_manager.cpp +++ b/code/nel/src/gui/lua_manager.cpp @@ -33,8 +33,20 @@ namespace NLGUI CLuaManager::~CLuaManager() { - delete luaState; - luaState = NULL; + if (luaState) + { + delete luaState; + luaState = NULL; + } + } + + void CLuaManager::releaseInstance() + { + if (instance) + { + delete instance; + instance = NULL; + } } bool CLuaManager::executeLuaScript( const std::string &luaScript, bool smallScript ) @@ -60,7 +72,8 @@ namespace NLGUI void CLuaManager::ResetLuaState() { - delete luaState; + if (luaState) delete luaState; + luaState = new CLuaState( debugLua ); } diff --git a/code/ryzom/client/src/release.cpp b/code/ryzom/client/src/release.cpp index f88849197..e2a96c397 100644 --- a/code/ryzom/client/src/release.cpp +++ b/code/ryzom/client/src/release.cpp @@ -659,7 +659,7 @@ void release() CInterfaceExpr::release(); CPdrTokenRegistry::releaseInstance(); NLNET::IModuleManager::releaseInstance(); - delete &CLuaManager::getInstance(); + CLuaManager::releaseInstance(); NLGUI::CDBManager::release(); CWidgetManager::release();