fixed a bug where double dependencies could cause a crash on unload
authorDavid Anderson <dvander@alliedmods.net>
Sun Sep 23 06:51:21 2007 +0000 (2007-09-23)
changeset 145669a68787c743
parent 1455 60b3b783bed8
child 1457 591c38df0b47
fixed a bug where double dependencies could cause a crash on unload
core/sourcemod.cpp
core/sourcemod.h
core/systems/ExtensionSys.cpp
core/systems/ShareSys.h
     1.1 --- a/core/sourcemod.cpp	Sun Sep 23 00:35:28 2007 +0000
     1.2 +++ b/core/sourcemod.cpp	Sun Sep 23 06:51:21 2007 +0000
     1.3 @@ -63,7 +63,6 @@
     1.4  IdentityToken_t *g_pCoreIdent = NULL;
     1.5  IForward *g_pOnMapEnd = NULL;
     1.6  bool g_Loaded = false;
     1.7 -IExtension *g_pGameExt = NULL;
     1.8  
     1.9  typedef int (*GIVEENGINEPOINTER)(ISourcePawnEngine *);
    1.10  typedef int (*GIVEENGINEPOINTER2)(ISourcePawnEngine *, unsigned int api_version);
    1.11 @@ -406,8 +405,8 @@
    1.12  	if ((game_ext = g_pGameConf->GetKeyValue("GameExtension")) != NULL)
    1.13  	{
    1.14  		char path[PLATFORM_MAX_PATH];
    1.15 -		UTIL_Format(path, sizeof(path), "%s.ext." PLATFORM_LIB_EXT, game_ext);
    1.16 -		g_pGameExt = g_Extensions.LoadAutoExtension(path);
    1.17 +		UTIL_Format(path, sizeof(path), "games/%s.ext." PLATFORM_LIB_EXT, game_ext);
    1.18 +		g_Extensions.LoadAutoExtension(path);
    1.19  	}
    1.20  
    1.21  	/* Run the first pass */
     2.1 --- a/core/sourcemod.h	Sun Sep 23 00:35:28 2007 +0000
     2.2 +++ b/core/sourcemod.h	Sun Sep 23 06:51:21 2007 +0000
     2.3 @@ -131,6 +131,5 @@
     2.4  extern SourceModBase g_SourceMod;
     2.5  extern HandleType_t g_WrBitBufType;		//:TODO: find a better place for this
     2.6  extern HandleType_t g_RdBitBufType;		//:TODO: find a better place for this
     2.7 -extern IExtension *g_pGameExt;
     2.8  
     2.9  #endif //_INCLUDE_SOURCEMOD_GLOBALHEADER_H_
     3.1 --- a/core/systems/ExtensionSys.cpp	Sun Sep 23 00:35:28 2007 +0000
     3.2 +++ b/core/systems/ExtensionSys.cpp	Sun Sep 23 06:51:21 2007 +0000
     3.3 @@ -205,7 +205,10 @@
     3.4  
     3.5  void CExtension::AddDependency(IfaceInfo *pInfo)
     3.6  {
     3.7 -	m_Deps.push_back(*pInfo);
     3.8 +	if (m_Deps.find(*pInfo) == m_Deps.end())
     3.9 +	{
    3.10 +		m_Deps.push_back(*pInfo);
    3.11 +	}
    3.12  }
    3.13  
    3.14  bool operator ==(const IfaceInfo &i1, const IfaceInfo &i2)
    3.15 @@ -393,7 +396,7 @@
    3.16  	if (!strstr(path, "." PLATFORM_LIB_EXT))
    3.17  	{
    3.18  		char newpath[PLATFORM_MAX_PATH];
    3.19 -		snprintf(newpath, PLATFORM_MAX_PATH, "%s.%s", path, PLATFORM_LIB_EXT);
    3.20 +		g_LibSys.PathFormat(newpath, sizeof(newpath), "%s.%s", path, PLATFORM_LIB_EXT);
    3.21  		return LoadAutoExtension(newpath);
    3.22  	}
    3.23  
    3.24 @@ -428,13 +431,13 @@
    3.25  	if (!strstr(file, "." PLATFORM_LIB_EXT))
    3.26  	{
    3.27  		char path[PLATFORM_MAX_PATH];
    3.28 -		snprintf(path, PLATFORM_MAX_PATH, "%s.%s", file, PLATFORM_LIB_EXT);
    3.29 +		UTIL_Format(path, sizeof(path), "%s.%s", file, PLATFORM_LIB_EXT);
    3.30  		return FindExtensionByFile(path);
    3.31  	}
    3.32  
    3.33  	/* Make sure the file direction is right */
    3.34  	char path[PLATFORM_MAX_PATH];
    3.35 -	g_LibSys.PathFormat(path, PLATFORM_MAX_PATH, "%s", file);
    3.36 +	g_LibSys.PathFormat(path, sizeof(path), "%s", file);
    3.37  
    3.38  	for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
    3.39  	{
    3.40 @@ -743,12 +746,6 @@
    3.41  		}
    3.42  	}
    3.43  
    3.44 -	/* :HACKHACK: make sure g_pGameExt gets cleared */
    3.45 -	if (pExt == g_pGameExt)
    3.46 -	{
    3.47 -		g_pGameExt = NULL;
    3.48 -	}
    3.49 -
    3.50  	delete pExt;
    3.51  
    3.52  	List<CExtension *>::iterator iter;
    3.53 @@ -945,12 +942,6 @@
    3.54  				return;
    3.55  			}
    3.56  
    3.57 -			if (pExt == g_pGameExt)
    3.58 -			{
    3.59 -				g_RootMenu.ConsolePrint("[SM] Game extensions cannot be unloaded at this time.");
    3.60 -				return;
    3.61 -			}
    3.62 -
    3.63  			if (argcount > 4 && pExt->unload_code)
    3.64  			{
    3.65  				const char *unload = g_RootMenu.GetArgument(4);
    3.66 @@ -960,7 +951,9 @@
    3.67  					snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename());
    3.68  					UnloadExtension(pExt);
    3.69  					g_RootMenu.ConsolePrint("[SM] Extension %s is now unloaded.", filename);
    3.70 -				} else {
    3.71 +				}
    3.72 +				else
    3.73 +				{
    3.74  					g_RootMenu.ConsolePrint("[SM] Please try again, the correct unload code is \"%d\"", pExt->unload_code);
    3.75  				}
    3.76  				return;
    3.77 @@ -974,7 +967,9 @@
    3.78  				UnloadExtension(pExt);
    3.79  				g_RootMenu.ConsolePrint("[SM] Extension %s is now unloaded.", filename);
    3.80  				return;
    3.81 -			} else {
    3.82 +			}
    3.83 +			else
    3.84 +			{
    3.85  				List<IPlugin *> plugins;
    3.86  				if (pExt->m_ChildDeps.size())
    3.87  				{
     4.1 --- a/core/systems/ShareSys.h	Sun Sep 23 00:35:28 2007 +0000
     4.2 +++ b/core/systems/ShareSys.h	Sun Sep 23 06:51:21 2007 +0000
     4.3 @@ -52,6 +52,10 @@
     4.4  
     4.5  struct IfaceInfo
     4.6  {
     4.7 +	bool operator ==(const IfaceInfo &info)
     4.8 +	{
     4.9 +		return (info.iface == iface && info.owner == owner);
    4.10 +	}
    4.11  	SMInterface *iface;
    4.12  	IExtension *owner;
    4.13  };