From 7c8be8a2b4b175830f381c429c7d9890dc16fcb7 Mon Sep 17 00:00:00 2001 From: Ross Bemrose Date: Wed, 4 Jun 2014 15:46:31 -0400 Subject: [PATCH 1/2] 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. --- extension.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ extension.h | 4 +++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/extension.cpp b/extension.cpp index b5c411f..88ac4e6 100644 --- a/extension.cpp +++ b/extension.cpp @@ -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; + } +} diff --git a/extension.h b/extension.h index fd7f7f0..203efec 100644 --- a/extension.h +++ b/extension.h @@ -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 /**