From 05814756666e54b5eb79c0112387447a0c347892 Mon Sep 17 00:00:00 2001 From: Leon Styhre <leon@leonstyhre.com> Date: Mon, 21 Jun 2021 17:02:26 +0200 Subject: [PATCH] Fixed a random crash when marking all or none of the games as favorites for a system or folder. --- es-app/src/views/gamelist/ISimpleGameListView.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/es-app/src/views/gamelist/ISimpleGameListView.cpp b/es-app/src/views/gamelist/ISimpleGameListView.cpp index 16bfb25ab..5cad9523b 100644 --- a/es-app/src/views/gamelist/ISimpleGameListView.cpp +++ b/es-app/src/views/gamelist/ISimpleGameListView.cpp @@ -286,6 +286,7 @@ bool ISimpleGameListView::input(InputConfig* config, Input input) // it gets after the gamelist sorting. Instead retain the cursor position in the // list using the logic below. FileData* entryToUpdate = getCursor(); + SystemData* system = getCursor()->getSystem(); bool favoritesSorting; bool removedLastFavorite = false; bool selectLastEntry = false; @@ -376,6 +377,7 @@ bool ISimpleGameListView::input(InputConfig* config, Input input) } setCursor(entryToSelect); + system = entryToUpdate->getSystem(); } // Marking folders as favorites don't make them part of any collections, @@ -429,6 +431,10 @@ bool ISimpleGameListView::input(InputConfig* config, Input input) mWindow->setInfoPopup(s); } else if (CollectionSystemsManager::get()->toggleGameInCollection(entryToUpdate)) { + // As the toggling of the game destroyed this object, we need to get the view + // from ViewController instead of using the reference that existed before the + // destruction. Otherwise we get random crashes. + IGameListView* view = ViewController::get()->getGameListView(system).get(); // Jump to the first entry in the gamelist if the last favorite was unmarked. if (foldersOnTop && removedLastFavorite && !entryToUpdate->getSystem()->isCustomCollection()) { @@ -438,10 +444,10 @@ bool ISimpleGameListView::input(InputConfig* config, Input input) } else if (removedLastFavorite && !entryToUpdate->getSystem()->isCustomCollection()) { - setCursor(getFirstEntry()); + view->setCursor(view->getFirstEntry()); } else if (selectLastEntry) { - setCursor(getLastEntry()); + view->setCursor(view->getLastEntry()); } // Display the indication icons which show what games are part of the // custom collection currently being edited. This is done cheaply using