Require that no plugin code be live when any plugin unloads.

This commit is contained in:
David Anderson 2015-10-31 19:38:30 -07:00
parent 59623695af
commit cb3f6df111
2 changed files with 17 additions and 8 deletions

View File

@ -1446,13 +1446,22 @@ bool CPluginManager::ScheduleUnload(CPlugin *pPlugin)
if (pPlugin->State() == PluginState::WaitingToUnload) if (pPlugin->State() == PluginState::WaitingToUnload)
return false; return false;
IPluginContext *pContext = pPlugin->GetBaseContext(); // It is not safe to unload any plugin while another is on the callstack.
if (pContext && pContext->IsInExec()) { bool any_active = false;
ke::Lambda<void()> callback = [this, pPlugin]() { for (PluginIter iter(m_plugins); !iter.done(); iter.next()) {
this->ScheduleUnload(pPlugin); if (IPluginContext *context = (*iter)->GetBaseContext()) {
}; if (context->IsInExec()) {
any_active = true;
break;
}
}
}
if (any_active) {
pPlugin->SetWaitingToUnload(); pPlugin->SetWaitingToUnload();
ScheduleTaskForNextFrame(ke::Move(callback)); ScheduleTaskForNextFrame([this, pPlugin] () -> void {
ScheduleUnload(pPlugin);
});
return false; return false;
} }
@ -1463,7 +1472,6 @@ bool CPluginManager::ScheduleUnload(CPlugin *pPlugin)
void CPluginManager::Purge(CPlugin *plugin) void CPluginManager::Purge(CPlugin *plugin)
{ {
// Go through our libraries and tell other plugins they're gone. // Go through our libraries and tell other plugins they're gone.
plugin->LibraryActions(LibraryAction_Removed); plugin->LibraryActions(LibraryAction_Removed);

View File

@ -1,5 +1,5 @@
/** /**
* vim: set ts=4 : * vim: set ts=4 sw=4 tw=99 noet:
* ============================================================================= * =============================================================================
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved. * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
* ============================================================================= * =============================================================================
@ -92,6 +92,7 @@ enum PluginStatus
Plugin_Created, /**< Plugin is created but not initialized */ Plugin_Created, /**< Plugin is created but not initialized */
Plugin_Uncompiled, /**< Plugin is not yet compiled by the JIT */ Plugin_Uncompiled, /**< Plugin is not yet compiled by the JIT */
Plugin_BadLoad, /**< Plugin failed to load */ Plugin_BadLoad, /**< Plugin failed to load */
Plugin_Evicted /**< Plugin was unloaded due to an error */
}; };
/** /**