From 94543467822401b407f4b061268e42d59d6a905b Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Wed, 1 Jan 2020 08:19:48 +0100 Subject: ENGINES: Copy the data referenced by QualifiedGameDescriptor The engineId, gameId and description come from static data in the game engines. When the game engines are compiled as dynamic plugins, the QGD structure may outlive the engine plugin. Making a copy ensures the data remains available. Fixes #11292. --- base/commandLine.cpp | 8 ++++---- base/main.cpp | 2 +- engines/game.cpp | 14 +++----------- engines/game.h | 8 +++++--- gui/editgamedialog.cpp | 2 +- gui/launcher.cpp | 2 +- 6 files changed, 15 insertions(+), 21 deletions(-) diff --git a/base/commandLine.cpp b/base/commandLine.cpp index c8ceea77af..bb7f93a274 100644 --- a/base/commandLine.cpp +++ b/base/commandLine.cpp @@ -804,7 +804,7 @@ static void listTargets() { // If there's no description, fallback on the default description. if (description.empty()) { QualifiedGameDescriptor g = EngineMan.findTarget(name); - if (g.description) + if (!g.description.empty()) description = g.description; } // If there's still no description, we cannot come up with one. Insert some dummy text. @@ -854,7 +854,7 @@ static Common::Error listSaves(const Common::String &singleTarget) { currentTarget = *i; EngineMan.upgradeTargetIfNecessary(*i); game = EngineMan.findTarget(*i, &plugin); - } else if (game = findGameMatchingName(*i), game.gameId) { + } else if (game = findGameMatchingName(*i), !game.gameId.empty()) { // The name is a known game id plugin = EngineMan.findPlugin(game.engineId); currentTarget = createTemporaryTarget(game.engineId, game.gameId); @@ -1278,7 +1278,7 @@ bool processSettings(Common::String &command, Common::StringMap &settings, Commo QualifiedGameDescriptor gameOption; if (settings.contains("game")) { gameOption = findGameMatchingName(settings["game"]); - if (!gameOption.gameId) { + if (gameOption.gameId.empty()) { usage("Unrecognized game '%s'. Use the --list-games command for a list of accepted values.\n", settings["game"].c_str()); } } @@ -1361,7 +1361,7 @@ bool processSettings(Common::String &command, Common::StringMap &settings, Commo if (ConfMan.hasGameDomain(command)) { // Command is a known target ConfMan.setActiveDomain(command); - } else if (gd = findGameMatchingName(command), gd.gameId) { + } else if (gd = findGameMatchingName(command), !gd.gameId.empty()) { // Command is a known game ID Common::String domainName = createTemporaryTarget(gd.engineId, gd.gameId); ConfMan.setActiveDomain(domainName); diff --git a/base/main.cpp b/base/main.cpp index 8121d77c88..66ff457936 100644 --- a/base/main.cpp +++ b/base/main.cpp @@ -216,7 +216,7 @@ static Common::Error runGame(const Plugin *plugin, OSystem &system, const Common if (caption.empty()) { QualifiedGameDescriptor game = EngineMan.findTarget(ConfMan.getActiveDomainName()); - if (game.description) { + if (!game.description.empty()) { caption = game.description; } } diff --git a/engines/game.cpp b/engines/game.cpp index b706e1d976..b90381d2d3 100644 --- a/engines/game.cpp +++ b/engines/game.cpp @@ -49,18 +49,10 @@ PlainGameDescriptor PlainGameDescriptor::of(const char *gameId, const char *desc return pgd; } -QualifiedGameDescriptor::QualifiedGameDescriptor() : - PlainGameDescriptor() { - engineId = nullptr; - gameId = nullptr; - description = nullptr; -} - QualifiedGameDescriptor::QualifiedGameDescriptor(const char *engine, const PlainGameDescriptor &pgd) : - PlainGameDescriptor() { - engineId = engine; - gameId = pgd.gameId; - description = pgd.description; + engineId(engine), + gameId(pgd.gameId), + description(pgd.description) { } DetectedGame::DetectedGame() : diff --git a/engines/game.h b/engines/game.h index e378976cb1..8316857e24 100644 --- a/engines/game.h +++ b/engines/game.h @@ -66,10 +66,12 @@ public: /** * The description of a game supported by an engine */ -struct QualifiedGameDescriptor : public PlainGameDescriptor { - const char *engineId; +struct QualifiedGameDescriptor { + Common::String engineId; + Common::String gameId; + Common::String description; - QualifiedGameDescriptor(); + QualifiedGameDescriptor() {} QualifiedGameDescriptor(const char *engine, const PlainGameDescriptor &pgd); }; diff --git a/gui/editgamedialog.cpp b/gui/editgamedialog.cpp index c2953dc8e5..6c553f8783 100644 --- a/gui/editgamedialog.cpp +++ b/gui/editgamedialog.cpp @@ -121,7 +121,7 @@ EditGameDialog::EditGameDialog(const String &domain) // GAME: Determine the description string String description(ConfMan.get("description", domain)); - if (description.empty() && qgd.description) { + if (description.empty() && !qgd.description.empty()) { description = qgd.description; } diff --git a/gui/launcher.cpp b/gui/launcher.cpp index 94af6472a5..21937494c4 100644 --- a/gui/launcher.cpp +++ b/gui/launcher.cpp @@ -284,7 +284,7 @@ void LauncherDialog::updateListing() { if (description.empty()) { QualifiedGameDescriptor g = EngineMan.findTarget(iter->_key); - if (g.description) + if (!g.description.empty()) description = g.description; } -- cgit v1.2.3