1.1 --- a/sourcemm/sourcemm.cpp Sat Sep 24 15:56:40 2005 +0000
1.2 +++ b/sourcemm/sourcemm.cpp Sat Sep 24 21:10:53 2005 +0000
1.3 @@ -37,7 +37,6 @@
1.4 SourceHook::String g_ModPath;
1.5 SourceHook::String g_BinPath;
1.6 PluginId g_PLID = Pl_Console; //Technically, SourceMM is the "Console" plugin... :p
1.7 -bool bInShutdown = false;
1.8 bool bInFirstLevel = true;
1.9
1.10 ///////////////////////////////////
1.11 @@ -268,44 +267,21 @@
1.12 g_SMConVarAccessor.MarkCommandsAsGameDLL();
1.13 }
1.14
1.15 -// The engine uses the DLL even after it has call DLLShutdown, so we unload it
1.16 -// when it unloads us
1.17 -#if defined _WIN32
1.18 - BOOL WINAPI DllMain(
1.19 - HINSTANCE hinstDLL,
1.20 - DWORD fdwReason,
1.21 - LPVOID lpvReserved
1.22 - )
1.23 - {
1.24 - if (fdwReason == DLL_PROCESS_DETACH)
1.25 - {
1.26 - if (!bInShutdown)
1.27 - Shutdown();
1.28 - if (g_GameDll.lib && g_GameDll.loaded)
1.29 - dlclose(g_GameDll.lib);
1.30 - memset(&g_GameDll, 0, sizeof(GameDllInfo));
1.31 - }
1.32 - return TRUE;
1.33 - }
1.34 -#elif defined __linux__
1.35 - void __attribute__ ((destructor)) app_fini(void)
1.36 - {
1.37 - if (!bInShutdown)
1.38 - Shutdown();
1.39 - if (g_GameDll.lib && g_GameDll.loaded)
1.40 - dlclose(g_GameDll.lib);
1.41 - memset(&g_GameDll, 0, sizeof(GameDllInfo));
1.42 - }
1.43 -#endif
1.44 -
1.45 void CServerGameDLL::DLLShutdown()
1.46 {
1.47 Shutdown();
1.48
1.49 - //Call the original function
1.50 + //Call the original function
1.51 m_pOrig->DLLShutdown();
1.52
1.53 - bInShutdown = true;
1.54 + //Unregister all commands marked as GameDLL now
1.55 + //This prevents crashes when the engine tries to unregister them once we have already unloaded the gamedll
1.56 + //(we used to unload the gamedll in a __attribute__((destructor)) function but I've had problems with that (crashes in dlclose)
1.57 + g_SMConVarAccessor.UnregisterGameDLLCommands();
1.58 +
1.59 + if (g_GameDll.lib && g_GameDll.loaded)
1.60 + dlclose(g_GameDll.lib);
1.61 + memset(&g_GameDll, 0, sizeof(GameDllInfo));
1.62 }
1.63
1.64 int LoadPluginsFromFile(const char *file)