Fix a crash if SDKHooks was unloaded before us. Also, stop working if any of

our dependencies are unloaded.
Note: Bintools was added to the list of dependencies checked.
This commit is contained in:
Ross Bemrose 2014-06-04 15:46:31 -04:00
parent 9574a647af
commit 7c8be8a2b4
2 changed files with 47 additions and 1 deletions

View File

@ -110,3 +110,47 @@ void DHooks::OnPluginUnloaded(IPlugin *plugin)
g_pEntityListener->CleanupListeners(plugin->GetBaseContext());
}
}
// The next 3 functions handle cleanup if our interfaces are going to be unloaded
bool DHooks::QueryRunning(char *error, size_t maxlength)
{
SM_CHECK_IFACE(SDKTOOLS, g_pSDKTools);
SM_CHECK_IFACE(BINTOOLS, g_pBinTools);
SM_CHECK_IFACE(SDKHOOKS, g_pSDKHooks);
return true;
}
/*
// The default for this one is *supposed* to be false already
bool DHooks::QueryInterfaceDrop(SMInterface *pInterface)
{
if (strcmp(pInterface->GetInterfaceName(), SMINTERFACE_SDKTOOLS_NAME) == 0
|| strcmp(pInterface->GetInterfaceName(), SMINTERFACE_BINTOOL_NAME) == 0)
|| strcmp(pInterface->GetInterfaceName(), SMINTERFACE_SDKHOOKS_NAME) == 0)
{
return false;
}
return true;
}
*/
void DHooks::NotifyInterfaceDrop(SMInterface *pInterface)
{
if (strcmp(pInterface->GetInterfaceName(), SMINTERFACE_SDKHOOKS_NAME) == 0)
{
if (g_pEntityListener)
{
// If this fails, remove this line and just delete the ent listener instead
g_pSDKHooks->RemoveEntityListener(g_pEntityListener);
delete g_pEntityListener;
g_pEntityListener = NULL;
}
g_pSDKHooks = NULL;
}
else if (strcmp(pInterface->GetInterfaceName(), SMINTERFACE_BINTOOLS_NAME) == 0)
{
g_pBinTools = NULL;
}
else if (strcmp(pInterface->GetInterfaceName(), SMINTERFACE_SDKTOOLS_NAME) == 0)
{
g_pSDKTools = NULL;
}
}

View File

@ -88,7 +88,9 @@ public:
* @param maxlength Size of error message buffer.
* @return True if working, false otherwise.
*/
//virtual bool QueryRunning(char *error, size_t maxlength);
virtual bool QueryRunning(char *error, size_t maxlength);
//virtual bool QueryInterfaceDrop(SMInterface *pInterface);
virtual void NotifyInterfaceDrop(SMInterface *pInterface);
public:
#if defined SMEXT_CONF_METAMOD
/**