From c4095aabc5bb2d53bb8bb1c97e94f39cf3d81355 Mon Sep 17 00:00:00 2001 From: Yotam Barnoy Date: Sun, 2 Jan 2011 10:08:02 +0000 Subject: PLUGINS: for uncached plugins, first check the loaded plugin before looking elsewhere There are some calls to EngineManager::findGame() from within games, such as when loading saved games. It's critical not to unload the plugin from memory or other threads may crash. Therefore, we first scan using any plugin that's already in memory. svn-id: r55089 --- base/plugins.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'base/plugins.cpp') diff --git a/base/plugins.cpp b/base/plugins.cpp index a46ebe8748..5f01329df8 100644 --- a/base/plugins.cpp +++ b/base/plugins.cpp @@ -344,6 +344,7 @@ void PluginManagerUncached::init() { // Resize our pluginsInMem list to prevent fragmentation _pluginsInMem[PLUGIN_TYPE_ENGINE].resize(2); + unloadPluginsExcept(PLUGIN_TYPE_ENGINE, NULL, false); // empty the engine plugins for (ProviderList::iterator pp = _providers.begin(); pp != _providers.end(); @@ -543,8 +544,16 @@ DECLARE_SINGLETON(EngineManager); **/ GameDescriptor EngineManager::findGame(const Common::String &gameName, const EnginePlugin **plugin) const { GameDescriptor result; + + // First look for the game using the plugins in memory. This is critical + // for calls coming from inside games + result = findGameInLoadedPlugins(gameName, plugin); + if (!result.gameid().empty()) { + return result; + } - // first look for the game using the gameId + // Now look for the game using the gameId. This is much faster than scanning plugin + // by plugin if (PluginMan.loadPluginFromGameId(gameName)) { result = findGameInLoadedPlugins(gameName, plugin); if (!result.gameid().empty()) { -- cgit v1.2.3