BASE: Remove bad casts between incompatible Plugin types

Previously, a C-style cast was used to convert a
Common::Array<Plugin *>, populated with pointers to StaticPlugin
and DynamicPlugin instances, to a
Common::Array<PluginSubclass<T> *>, but PluginSubclass<T> 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.
This commit is contained in:
Colin Snover 2017-11-10 23:06:42 -06:00
parent 55855cab83
commit d087c9605f
17 changed files with 117 additions and 132 deletions

View file

@ -76,14 +76,14 @@ Common::String SaveLoadChooser::createDefaultSaveDescription(const int slot) con
int SaveLoadChooser::runModalWithCurrentTarget() {
const Common::String gameId = ConfMan.get("gameid");
const EnginePlugin *plugin = 0;
const Plugin *plugin = 0;
EngineMan.findGame(gameId, &plugin);
return runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
}
int SaveLoadChooser::runModalWithPluginAndTarget(const EnginePlugin *plugin, const String &target) {
selectChooser(**plugin);
int SaveLoadChooser::runModalWithPluginAndTarget(const Plugin *plugin, const String &target) {
selectChooser(plugin->get<MetaEngine>());
if (!_impl)
return -1;
@ -98,10 +98,10 @@ int SaveLoadChooser::runModalWithPluginAndTarget(const EnginePlugin *plugin, con
int ret;
do {
ret = _impl->run(target, &(**plugin));
ret = _impl->run(target, &plugin->get<MetaEngine>());
#ifndef DISABLE_SAVELOADCHOOSER_GRID
if (ret == kSwitchSaveLoadDialog) {
selectChooser(**plugin);
selectChooser(plugin->get<MetaEngine>());
}
#endif // !DISABLE_SAVELOADCHOOSER_GRID
} while (ret < -1);