- 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
This commit is contained in:
David Anderson 2007-06-26 17:08:07 +00:00
parent 5e7b7589be
commit 271a8b5b56
5 changed files with 34 additions and 0 deletions

View File

@ -498,6 +498,15 @@ size_t SourceModBase::BuildPath(PathType type, char *buffer, size_t maxlength, c
void SourceModBase::CloseSourceMod() 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); SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &SourceModBase::LevelInit, false);
if (g_Loaded) if (g_Loaded)

View File

@ -280,6 +280,16 @@ void CExtensionManager::OnSourceModShutdown()
g_ShareSys.DestroyIdentType(g_ExtType); g_ShareSys.DestroyIdentType(g_ExtType);
} }
void CExtensionManager::Shutdown()
{
List<CExtension *>::iterator iter;
while ((iter = m_Libs.begin()) != m_Libs.end())
{
UnloadExtension((*iter));
}
}
void CExtensionManager::TryAutoload() void CExtensionManager::TryAutoload()
{ {
char path[PLATFORM_MAX_PATH]; char path[PLATFORM_MAX_PATH];
@ -603,6 +613,8 @@ bool CExtensionManager::UnloadExtension(IExtension *_pExt)
} }
} }
delete pExt;
List<CExtension *>::iterator iter; List<CExtension *>::iterator iter;
for (iter=UnloadQueue.begin(); iter!=UnloadQueue.end(); iter++) for (iter=UnloadQueue.begin(); iter!=UnloadQueue.end(); iter++)
{ {

View File

@ -101,6 +101,7 @@ public:
void TryAutoload(); void TryAutoload();
public: public:
CExtension *GetExtensionFromIdent(IdentityToken_t *ptr); CExtension *GetExtensionFromIdent(IdentityToken_t *ptr);
void Shutdown();
private: private:
CExtension *FindByOrder(unsigned int num); CExtension *FindByOrder(unsigned int num);
private: private:

View File

@ -716,6 +716,16 @@ CPluginManager::~CPluginManager()
m_iters.popall(); m_iters.popall();
} }
void CPluginManager::Shutdown()
{
List<CPlugin *>::iterator iter;
while ((iter = m_plugins.begin()) != m_plugins.end())
{
UnloadPlugin(*iter);
}
}
void CPluginManager::LoadAll_FirstPass(const char *config, const char *basedir) void CPluginManager::LoadAll_FirstPass(const char *config, const char *basedir)
{ {
/* First read in the database of plugin settings */ /* First read in the database of plugin settings */

View File

@ -376,6 +376,8 @@ public:
CPlugin *GetPluginFromIdentity(IdentityToken_t *pToken); CPlugin *GetPluginFromIdentity(IdentityToken_t *pToken);
void Shutdown();
private: private:
LoadRes _LoadPlugin(CPlugin **pPlugin, const char *path, bool debug, PluginType type, char error[], size_t maxlength); LoadRes _LoadPlugin(CPlugin **pPlugin, const char *path, bool debug, PluginType type, char error[], size_t maxlength);