From 654dc2a5468a66e5239e82c6697519d15118e56d Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Thu, 2 Dec 2021 17:34:30 +0100 Subject: [PATCH] Fixed a crash that could occur when aborting the single-scraper followed by a re-scrape. --- es-app/src/guis/GuiGameScraper.cpp | 16 ++++++++-------- es-app/src/guis/GuiGameScraper.h | 6 ++++-- es-app/src/guis/GuiMetaDataEd.cpp | 12 +++++++----- es-app/src/guis/GuiMetaDataEd.h | 1 + 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/es-app/src/guis/GuiGameScraper.cpp b/es-app/src/guis/GuiGameScraper.cpp index 5e9eab8c2..7b8c2dc97 100644 --- a/es-app/src/guis/GuiGameScraper.cpp +++ b/es-app/src/guis/GuiGameScraper.cpp @@ -19,13 +19,15 @@ #include "views/ViewController.h" GuiGameScraper::GuiGameScraper(Window* window, - ScraperSearchParams params, - std::function doneFunc) + ScraperSearchParams& params, + std::function doneFunc, + bool& savedMediaAndAborted) : GuiComponent(window) , mClose(false) , mGrid(window, glm::ivec2{2, 6}) , mBox(window, ":/graphics/frame.svg") , mSearchParams(params) + , mSavedMediaAndAborted(savedMediaAndAborted) { addChild(&mBox); addChild(&mGrid); @@ -169,12 +171,10 @@ bool GuiGameScraper::input(InputConfig* config, Input input) if (config->isMappedTo("b", input) && input.value) { if (mSearch->getSavedNewMedia()) { // If the user aborted the scraping but there was still some media downloaded, - // then force an unload of the textures for the game image and marquee, and make - // an update of the game entry. Otherwise the images would not get updated until - // the user scrolls up and down the gamelist. - TextureResource::manualUnload(mSearchParams.game->getImagePath(), false); - TextureResource::manualUnload(mSearchParams.game->getMarqueePath(), false); - ViewController::get()->onFileChanged(mSearchParams.game, true); + // then flag to GuiMetaDataEd that the image and marquee textures need to be + // manually unloaded and that the gamelist needs to be reloaded. Otherwise the + // images would not get updated until the user scrolls up and down the gamelist. + mSavedMediaAndAborted = true; } delete this; return true; diff --git a/es-app/src/guis/GuiGameScraper.h b/es-app/src/guis/GuiGameScraper.h index 040f1e072..1bc648dcb 100644 --- a/es-app/src/guis/GuiGameScraper.h +++ b/es-app/src/guis/GuiGameScraper.h @@ -20,8 +20,9 @@ class GuiGameScraper : public GuiComponent { public: GuiGameScraper(Window* window, - ScraperSearchParams params, - std::function doneFunc); + ScraperSearchParams& params, + std::function doneFunc, + bool& savedMediaAndAborted); void onSizeChanged() override; @@ -48,6 +49,7 @@ private: std::shared_ptr mResultList; ScraperSearchParams mSearchParams; + bool& mSavedMediaAndAborted; std::function mCancelFunc; }; diff --git a/es-app/src/guis/GuiMetaDataEd.cpp b/es-app/src/guis/GuiMetaDataEd.cpp index 77c68f4ca..8d839090c 100644 --- a/es-app/src/guis/GuiMetaDataEd.cpp +++ b/es-app/src/guis/GuiMetaDataEd.cpp @@ -52,6 +52,7 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window, , mClearGameFunc{clearGameFunc} , mDeleteGameFunc{deleteGameFunc} , mMediaFilesUpdated{false} + , mSavedMediaAndAborted{false} , mInvalidEmulatorEntry{false} { mControllerBadges = BadgeComponent::getGameControllers(); @@ -719,7 +720,8 @@ void GuiMetaDataEd::save() void GuiMetaDataEd::fetch() { GuiGameScraper* scr = new GuiGameScraper( - mWindow, mScraperParams, std::bind(&GuiMetaDataEd::fetchDone, this, std::placeholders::_1)); + mWindow, mScraperParams, std::bind(&GuiMetaDataEd::fetchDone, this, std::placeholders::_1), + mSavedMediaAndAborted); mWindow->pushGui(scr); } @@ -791,11 +793,11 @@ void GuiMetaDataEd::close() std::function closeFunc; closeFunc = [this] { - if (mMediaFilesUpdated) { + if (mMediaFilesUpdated || mSavedMediaAndAborted) { // Always reload the gamelist if media files were updated, even if the user - // chose to not save any metadata changes. Also manually unload the game image - // and marquee, as otherwise they would not get updated until the user scrolls up - // and down the gamelist. + // chose to not save any metadata changes or aborted the scraping. Also manually + // unload the game image and marquee, as otherwise they would not get updated + // until the user scrolls up and down the gamelist. TextureResource::manualUnload(mScraperParams.game->getImagePath(), false); TextureResource::manualUnload(mScraperParams.game->getMarqueePath(), false); ViewController::get()->reloadGameListView(mScraperParams.system); diff --git a/es-app/src/guis/GuiMetaDataEd.h b/es-app/src/guis/GuiMetaDataEd.h index ec4ca13af..3ef87e441 100644 --- a/es-app/src/guis/GuiMetaDataEd.h +++ b/es-app/src/guis/GuiMetaDataEd.h @@ -71,6 +71,7 @@ private: std::function mDeleteGameFunc; bool mMediaFilesUpdated; + bool mSavedMediaAndAborted; bool mInvalidEmulatorEntry; };