From d087c9605ffffdc9053c5efdc83f53658afbe9a6 Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Fri, 10 Nov 2017 23:06:42 -0600 Subject: BASE: Remove bad casts between incompatible Plugin types Previously, a C-style cast was used to convert a Common::Array, populated with pointers to StaticPlugin and DynamicPlugin instances, to a Common::Array *>, but PluginSubclass is a *sibling* class to StaticPlugin/DynamicPlugin, so this cast was invalid and the results undefined. The methods for retrieving subclasses of plugins can't be easily changed to just generate an array of temporary wrapper objects that expose an identical API which dereferences to the preferred PluginObject subclass because pointers to these objects are retained by other parts of ScummVM, so the wrappers would needed to be persisted or they would need to just re-expose the underlying Plugin object again. This indicated that a way to solve this problem is to have the callers receive Plugin objects and get the PluginObject from the Plugin by explicitly stating their desired type, in a similar manner to std::get(std::variant), so that the pattern used by this patch to solve the problem. Closes gh-1051. --- engines/pegasus/pegasus.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/pegasus/pegasus.cpp') diff --git a/engines/pegasus/pegasus.cpp b/engines/pegasus/pegasus.cpp index 5f756449dd..f2c0afba5c 100644 --- a/engines/pegasus/pegasus.cpp +++ b/engines/pegasus/pegasus.cpp @@ -356,7 +356,7 @@ Common::Error PegasusEngine::showLoadDialog() { Common::String gameId = ConfMan.get("gameid"); - const EnginePlugin *plugin = 0; + const Plugin *plugin = nullptr; EngineMan.findGame(gameId, &plugin); int slot = slc.runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); @@ -380,7 +380,7 @@ Common::Error PegasusEngine::showSaveDialog() { Common::String gameId = ConfMan.get("gameid"); - const EnginePlugin *plugin = 0; + const Plugin *plugin = nullptr; EngineMan.findGame(gameId, &plugin); int slot = slc.runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); -- cgit v1.2.3