Fixed a crash that could occur when aborting the single-scraper followed by a re-scrape.

This commit is contained in:
Leon Styhre 2021-12-02 17:34:30 +01:00
parent c470abf2da
commit 654dc2a546
4 changed files with 20 additions and 15 deletions

View file

@ -19,13 +19,15 @@
#include "views/ViewController.h"
GuiGameScraper::GuiGameScraper(Window* window,
ScraperSearchParams params,
std::function<void(const ScraperSearchResult&)> doneFunc)
ScraperSearchParams& params,
std::function<void(const ScraperSearchResult&)> 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;

View file

@ -20,8 +20,9 @@ class GuiGameScraper : public GuiComponent
{
public:
GuiGameScraper(Window* window,
ScraperSearchParams params,
std::function<void(const ScraperSearchResult&)> doneFunc);
ScraperSearchParams& params,
std::function<void(const ScraperSearchResult&)> doneFunc,
bool& savedMediaAndAborted);
void onSizeChanged() override;
@ -48,6 +49,7 @@ private:
std::shared_ptr<ComponentList> mResultList;
ScraperSearchParams mSearchParams;
bool& mSavedMediaAndAborted;
std::function<void()> mCancelFunc;
};

View file

@ -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<void()> 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);

View file

@ -71,6 +71,7 @@ private:
std::function<void()> mDeleteGameFunc;
bool mMediaFilesUpdated;
bool mSavedMediaAndAborted;
bool mInvalidEmulatorEntry;
};