Skip to content

Commit

Permalink
Fix trying to call hook removal callback on unloaded plugin
Browse files Browse the repository at this point in the history
When a plugin which registered an entity vtable hook with a remove callback is unloaded OnMapEnd, dhooks still tried to call the removal callback on the next frame after the map ended and all entities were destroyed.

Remove the plugin's hooks from the removal list when a plugin is unloaded. The hooks are free'd anyways.

Drifter321#3
  • Loading branch information
peace-maker committed Jun 7, 2020
1 parent 86bfea5 commit ac44af9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ bool DHooks::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, boo

void DHooks::OnPluginUnloaded(IPlugin *plugin)
{
CleanupHooks(plugin->GetBaseContext());
RemoveAllCallbacksForContext(plugin->GetBaseContext());
if(g_pEntityListener)
{
g_pEntityListener->CleanupListeners(plugin->GetBaseContext());
}
CleanupHooks(plugin->GetBaseContext());
RemoveAllCallbacksForContext(plugin->GetBaseContext());
}
// The next 3 functions handle cleanup if our interfaces are going to be unloaded
bool DHooks::QueryRunning(char *error, size_t maxlength)
Expand Down
8 changes: 8 additions & 0 deletions listeners.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ void DHooksEntityListener::CleanupListeners(IPluginContext *pContext)
g_EntityListeners.remove(i);
}
}
for (int i = g_pRemoveList.length() -1; i >= 0; i--)
{
DHooksManager *manager = g_pRemoveList.at(i);
if (pContext == NULL || pContext == manager->callback->plugin_callback->GetParentRuntime()->GetDefaultContext())
{
g_pRemoveList.remove(i);
}
}
}

void DHooksEntityListener::OnEntityCreated(CBaseEntity *pEntity, const char *classname)
Expand Down

0 comments on commit ac44af9

Please sign in to comment.