diff --git a/core/logic/PluginSys.cpp b/core/logic/PluginSys.cpp index e359fe17..db2ed3a5 100644 --- a/core/logic/PluginSys.cpp +++ b/core/logic/PluginSys.cpp @@ -1446,13 +1446,22 @@ bool CPluginManager::ScheduleUnload(CPlugin *pPlugin) if (pPlugin->State() == PluginState::WaitingToUnload) return false; - IPluginContext *pContext = pPlugin->GetBaseContext(); - if (pContext && pContext->IsInExec()) { - ke::Lambda callback = [this, pPlugin]() { - this->ScheduleUnload(pPlugin); - }; + // It is not safe to unload any plugin while another is on the callstack. + bool any_active = false; + for (PluginIter iter(m_plugins); !iter.done(); iter.next()) { + if (IPluginContext *context = (*iter)->GetBaseContext()) { + if (context->IsInExec()) { + any_active = true; + break; + } + } + } + + if (any_active) { pPlugin->SetWaitingToUnload(); - ScheduleTaskForNextFrame(ke::Move(callback)); + ScheduleTaskForNextFrame([this, pPlugin] () -> void { + ScheduleUnload(pPlugin); + }); return false; } @@ -1463,7 +1472,6 @@ bool CPluginManager::ScheduleUnload(CPlugin *pPlugin) void CPluginManager::Purge(CPlugin *plugin) { - // Go through our libraries and tell other plugins they're gone. plugin->LibraryActions(LibraryAction_Removed); diff --git a/plugins/include/core.inc b/plugins/include/core.inc index 709690bb..f859ab9c 100644 --- a/plugins/include/core.inc +++ b/plugins/include/core.inc @@ -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. * ============================================================================= @@ -92,6 +92,7 @@ enum PluginStatus Plugin_Created, /**< Plugin is created but not initialized */ Plugin_Uncompiled, /**< Plugin is not yet compiled by the JIT */ Plugin_BadLoad, /**< Plugin failed to load */ + Plugin_Evicted /**< Plugin was unloaded due to an error */ }; /**