1
0
mirror of https://github.com/alliedmodders/metamod-source.git synced 2025-02-22 15:54:14 +01:00

Attempt at fixing some bugs related to gamedll shutdown

--HG--
extra : convert_revision : svn%3Ac2935e3e-5518-0410-8daf-afa5dab7d4e3/trunk%4083
This commit is contained in:
David Anderson 2005-06-26 19:15:24 +00:00
parent 5f2a28d33d
commit 5f6e613e01
3 changed files with 35 additions and 30 deletions

View File

@ -30,11 +30,11 @@ CPluginManager::CPluginManager()
CPluginManager::~CPluginManager() CPluginManager::~CPluginManager()
{ {
if (m_Plugins.size()) /*if (m_Plugins.size())
{ {
UnloadAll(); UnloadAll();
m_Plugins.clear(); m_Plugins.clear();
} }*/
} }
CPluginManager::CPlugin::CPlugin() : m_Lib(NULL), m_API(NULL), m_Id(0), m_Source(0) CPluginManager::CPlugin::CPlugin() : m_Lib(NULL), m_API(NULL), m_Id(0), m_Source(0)
@ -388,30 +388,23 @@ bool CPluginManager::_Unpause(CPluginManager::CPlugin *pl, char *error, size_t m
bool CPluginManager::UnloadAll() bool CPluginManager::UnloadAll()
{ {
PluginIter i; PluginIter i;
bool status = true;
std::list<SourceMM::CPluginManager::CPlugin *> remqueue;
for (i=m_Plugins.begin(); i!=m_Plugins.end(); i++) for (i=m_Plugins.begin(); i!=m_Plugins.end(); i++)
remqueue.push_back( (*i) );
char error[128];
bool status = true;
for (i=remqueue.begin(); i!=remqueue.end(); i++)
{ {
if ( (*i) ) if ( !_Unload( (*i), true, error, sizeof(error)-1) )
{
if ( (*i)->m_API )
{
if ( !(*i)->m_API->Unload(NULL, 0) )
status = false; status = false;
UnregAllConCmds( (*i) );
//Unlink from SourceHook
g_SourceHook.UnloadPlugin( (*i)->m_Id );
//Free the DLL
dlclose( (*i)->m_Lib );
}
delete (*i);
}
} }
m_Plugins.clear(); m_Plugins.clear();
remqueue.clear();
return status; return status;
} }

View File

@ -256,6 +256,18 @@ bool CServerGameDLL::DLLInit(CreateInterfaceFn engineFactory, CreateInterfaceFn
return false; return false;
} }
void Shutdown()
{
//Unload plugins
g_PluginMngr.UnloadAll();
// Shutdown sourcehook now
g_SourceHook.CompleteShutdown();
// Add the FCVAR_GAMEDLL flag to our cvars so the engine removes them properly
g_SMConVarAccessor.MarkCommandsAsGameDLL();
}
// The engine uses the DLL even after it has call DLLShutdown, so we unload it // The engine uses the DLL even after it has call DLLShutdown, so we unload it
// when it unloads us // when it unloads us
#if defined _WIN32 #if defined _WIN32
@ -267,6 +279,8 @@ bool CServerGameDLL::DLLInit(CreateInterfaceFn engineFactory, CreateInterfaceFn
{ {
if (fdwReason == DLL_PROCESS_DETACH) if (fdwReason == DLL_PROCESS_DETACH)
{ {
if (!bInShutdown)
Shutdown();
if (g_GameDll.lib && g_GameDll.loaded) if (g_GameDll.lib && g_GameDll.loaded)
dlclose(g_GameDll.lib); dlclose(g_GameDll.lib);
memset(&g_GameDll, 0, sizeof(GameDllInfo)); memset(&g_GameDll, 0, sizeof(GameDllInfo));
@ -276,6 +290,8 @@ bool CServerGameDLL::DLLInit(CreateInterfaceFn engineFactory, CreateInterfaceFn
#elif defined __linux__ #elif defined __linux__
void __attribute__ ((destructor)) app_fini(void) void __attribute__ ((destructor)) app_fini(void)
{ {
if (!bInShutdown())
Shutdown();
if (g_GameDll.lib && g_GameDll.loaded) if (g_GameDll.lib && g_GameDll.loaded)
dlclose(g_GameDll.lib); dlclose(g_GameDll.lib);
memset(&g_GameDll, 0, sizeof(GameDllInfo)); memset(&g_GameDll, 0, sizeof(GameDllInfo));
@ -284,17 +300,12 @@ bool CServerGameDLL::DLLInit(CreateInterfaceFn engineFactory, CreateInterfaceFn
void CServerGameDLL::DLLShutdown() void CServerGameDLL::DLLShutdown()
{ {
Shutdown();
//Call the original function //Call the original function
m_pOrig->DLLShutdown(); m_pOrig->DLLShutdown();
//Unload plugins bInShutdown = true;
g_PluginMngr.UnloadAll();
// Shutdown sourcehook now
g_SourceHook.CompleteShutdown();
// Add the FCVAR_GAMEDLL flag to our cvars so the engine removes them properly
g_SMConVarAccessor.MarkCommandsAsGameDLL();
} }
int LoadPluginsFromFile(const char *file) int LoadPluginsFromFile(const char *file)

View File

@ -31,12 +31,13 @@
Name="VCCustomBuildTool"/> Name="VCCustomBuildTool"/>
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="tier0.lib" AdditionalDependencies="tier0.lib vstdlib.lib"
OutputFile="$(OutDir)/sourcemm.dll" OutputFile="$(OutDir)/server.dll"
LinkIncremental="2" LinkIncremental="2"
GenerateDebugInformation="TRUE" GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/sourcemm.pdb" ProgramDatabaseFile="$(OutDir)/sourcemm.pdb"
SubSystem="2" SubSystem="2"
EnableCOMDATFolding="1"
ImportLibrary="$(OutDir)/sourcemm.lib" ImportLibrary="$(OutDir)/sourcemm.lib"
TargetMachine="1"/> TargetMachine="1"/>
<Tool <Tool