From 0059d92b618f4a737cc6e9e50d4d27e8a7f4bd05 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 23 Sep 2007 06:51:21 +0000 Subject: [PATCH] fixed a bug where double dependencies could cause a crash on unload --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401462 --- core/sourcemod.cpp | 5 ++--- core/sourcemod.h | 1 - core/systems/ExtensionSys.cpp | 31 +++++++++++++------------------ core/systems/ShareSys.h | 4 ++++ 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/core/sourcemod.cpp b/core/sourcemod.cpp index ada6343f..6acccda3 100644 --- a/core/sourcemod.cpp +++ b/core/sourcemod.cpp @@ -63,7 +63,6 @@ IVirtualMachine *g_pVM; IdentityToken_t *g_pCoreIdent = NULL; IForward *g_pOnMapEnd = NULL; bool g_Loaded = false; -IExtension *g_pGameExt = NULL; typedef int (*GIVEENGINEPOINTER)(ISourcePawnEngine *); typedef int (*GIVEENGINEPOINTER2)(ISourcePawnEngine *, unsigned int api_version); @@ -406,8 +405,8 @@ void SourceModBase::DoGlobalPluginLoads() if ((game_ext = g_pGameConf->GetKeyValue("GameExtension")) != NULL) { char path[PLATFORM_MAX_PATH]; - UTIL_Format(path, sizeof(path), "%s.ext." PLATFORM_LIB_EXT, game_ext); - g_pGameExt = g_Extensions.LoadAutoExtension(path); + UTIL_Format(path, sizeof(path), "games/%s.ext." PLATFORM_LIB_EXT, game_ext); + g_Extensions.LoadAutoExtension(path); } /* Run the first pass */ diff --git a/core/sourcemod.h b/core/sourcemod.h index 6a5f85de..378fff1f 100644 --- a/core/sourcemod.h +++ b/core/sourcemod.h @@ -131,6 +131,5 @@ private: extern SourceModBase g_SourceMod; extern HandleType_t g_WrBitBufType; //:TODO: find a better place for this extern HandleType_t g_RdBitBufType; //:TODO: find a better place for this -extern IExtension *g_pGameExt; #endif //_INCLUDE_SOURCEMOD_GLOBALHEADER_H_ diff --git a/core/systems/ExtensionSys.cpp b/core/systems/ExtensionSys.cpp index 87c1240d..bf30cec3 100644 --- a/core/systems/ExtensionSys.cpp +++ b/core/systems/ExtensionSys.cpp @@ -205,7 +205,10 @@ bool CExtension::IsLoaded() void CExtension::AddDependency(IfaceInfo *pInfo) { - m_Deps.push_back(*pInfo); + if (m_Deps.find(*pInfo) == m_Deps.end()) + { + m_Deps.push_back(*pInfo); + } } bool operator ==(const IfaceInfo &i1, const IfaceInfo &i2) @@ -393,7 +396,7 @@ IExtension *CExtensionManager::LoadAutoExtension(const char *path) if (!strstr(path, "." PLATFORM_LIB_EXT)) { char newpath[PLATFORM_MAX_PATH]; - snprintf(newpath, PLATFORM_MAX_PATH, "%s.%s", path, PLATFORM_LIB_EXT); + g_LibSys.PathFormat(newpath, sizeof(newpath), "%s.%s", path, PLATFORM_LIB_EXT); return LoadAutoExtension(newpath); } @@ -428,13 +431,13 @@ IExtension *CExtensionManager::FindExtensionByFile(const char *file) if (!strstr(file, "." PLATFORM_LIB_EXT)) { char path[PLATFORM_MAX_PATH]; - snprintf(path, PLATFORM_MAX_PATH, "%s.%s", file, PLATFORM_LIB_EXT); + UTIL_Format(path, sizeof(path), "%s.%s", file, PLATFORM_LIB_EXT); return FindExtensionByFile(path); } /* Make sure the file direction is right */ char path[PLATFORM_MAX_PATH]; - g_LibSys.PathFormat(path, PLATFORM_MAX_PATH, "%s", file); + g_LibSys.PathFormat(path, sizeof(path), "%s", file); for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++) { @@ -743,12 +746,6 @@ bool CExtensionManager::UnloadExtension(IExtension *_pExt) } } - /* :HACKHACK: make sure g_pGameExt gets cleared */ - if (pExt == g_pGameExt) - { - g_pGameExt = NULL; - } - delete pExt; List::iterator iter; @@ -945,12 +942,6 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmd, unsigned int argco return; } - if (pExt == g_pGameExt) - { - g_RootMenu.ConsolePrint("[SM] Game extensions cannot be unloaded at this time."); - return; - } - if (argcount > 4 && pExt->unload_code) { const char *unload = g_RootMenu.GetArgument(4); @@ -960,7 +951,9 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmd, unsigned int argco snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename()); UnloadExtension(pExt); g_RootMenu.ConsolePrint("[SM] Extension %s is now unloaded.", filename); - } else { + } + else + { g_RootMenu.ConsolePrint("[SM] Please try again, the correct unload code is \"%d\"", pExt->unload_code); } return; @@ -974,7 +967,9 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmd, unsigned int argco UnloadExtension(pExt); g_RootMenu.ConsolePrint("[SM] Extension %s is now unloaded.", filename); return; - } else { + } + else + { List plugins; if (pExt->m_ChildDeps.size()) { diff --git a/core/systems/ShareSys.h b/core/systems/ShareSys.h index 45666bc0..433506c3 100644 --- a/core/systems/ShareSys.h +++ b/core/systems/ShareSys.h @@ -52,6 +52,10 @@ namespace SourceMod struct IfaceInfo { + bool operator ==(const IfaceInfo &info) + { + return (info.iface == iface && info.owner == owner); + } SMInterface *iface; IExtension *owner; };