From 271a8b5b56936678bae0d26298fc3b101ef2b109 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 26 Jun 2007 17:08:07 +0000 Subject: [PATCH] - sourcemod can now unload properly without crashing - extensions now unload, dependencies are resolved --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401024 --- core/sourcemod.cpp | 9 +++++++++ core/systems/ExtensionSys.cpp | 12 ++++++++++++ core/systems/ExtensionSys.h | 1 + core/systems/PluginSys.cpp | 10 ++++++++++ core/systems/PluginSys.h | 2 ++ 5 files changed, 34 insertions(+) diff --git a/core/sourcemod.cpp b/core/sourcemod.cpp index 0142f3db..b01eee7f 100644 --- a/core/sourcemod.cpp +++ b/core/sourcemod.cpp @@ -498,6 +498,15 @@ size_t SourceModBase::BuildPath(PathType type, char *buffer, size_t maxlength, c void SourceModBase::CloseSourceMod() { + /* Force a level end */ + LevelShutdown(); + + /* Unload plugins */ + g_PluginSys.Shutdown(); + + /* Unload extensions */ + g_Extensions.Shutdown(); + SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &SourceModBase::LevelInit, false); if (g_Loaded) diff --git a/core/systems/ExtensionSys.cpp b/core/systems/ExtensionSys.cpp index faee31dc..50b374fc 100644 --- a/core/systems/ExtensionSys.cpp +++ b/core/systems/ExtensionSys.cpp @@ -280,6 +280,16 @@ void CExtensionManager::OnSourceModShutdown() g_ShareSys.DestroyIdentType(g_ExtType); } +void CExtensionManager::Shutdown() +{ + List::iterator iter; + + while ((iter = m_Libs.begin()) != m_Libs.end()) + { + UnloadExtension((*iter)); + } +} + void CExtensionManager::TryAutoload() { char path[PLATFORM_MAX_PATH]; @@ -603,6 +613,8 @@ bool CExtensionManager::UnloadExtension(IExtension *_pExt) } } + delete pExt; + List::iterator iter; for (iter=UnloadQueue.begin(); iter!=UnloadQueue.end(); iter++) { diff --git a/core/systems/ExtensionSys.h b/core/systems/ExtensionSys.h index 65b593ae..6c2da850 100644 --- a/core/systems/ExtensionSys.h +++ b/core/systems/ExtensionSys.h @@ -101,6 +101,7 @@ public: void TryAutoload(); public: CExtension *GetExtensionFromIdent(IdentityToken_t *ptr); + void Shutdown(); private: CExtension *FindByOrder(unsigned int num); private: diff --git a/core/systems/PluginSys.cpp b/core/systems/PluginSys.cpp index b630a68f..b5ed2383 100644 --- a/core/systems/PluginSys.cpp +++ b/core/systems/PluginSys.cpp @@ -716,6 +716,16 @@ CPluginManager::~CPluginManager() m_iters.popall(); } +void CPluginManager::Shutdown() +{ + List::iterator iter; + + while ((iter = m_plugins.begin()) != m_plugins.end()) + { + UnloadPlugin(*iter); + } +} + void CPluginManager::LoadAll_FirstPass(const char *config, const char *basedir) { /* First read in the database of plugin settings */ diff --git a/core/systems/PluginSys.h b/core/systems/PluginSys.h index 46d2fd14..8e9610fe 100644 --- a/core/systems/PluginSys.h +++ b/core/systems/PluginSys.h @@ -376,6 +376,8 @@ public: CPlugin *GetPluginFromIdentity(IdentityToken_t *pToken); + void Shutdown(); + private: LoadRes _LoadPlugin(CPlugin **pPlugin, const char *path, bool debug, PluginType type, char error[], size_t maxlength);