Fixed a few crashes related to GameSelectorComponent.

This commit is contained in:
Leon Styhre 2022-02-13 23:15:43 +01:00
parent 57a594225a
commit eb3729a5fb
3 changed files with 16 additions and 9 deletions

View file

@ -1096,7 +1096,7 @@ SystemData* SystemData::getRandomSystem(const SystemData* currentSystem)
return randomSystem;
}
FileData* SystemData::getRandomGame(const FileData* currentGame)
FileData* SystemData::getRandomGame(const FileData* currentGame, bool gameSelectorMode)
{
std::vector<FileData*> gameList;
bool onlyFolders = false;
@ -1109,12 +1109,17 @@ FileData* SystemData::getRandomGame(const FileData* currentGame)
gameList = mRootFolder->getParent()->getChildrenListToDisplay();
}
else {
gameList = ViewController::getInstance()
->getGamelistView(mRootFolder->getSystem())
.get()
->getCursor()
->getParent()
->getChildrenListToDisplay();
if (gameSelectorMode) {
gameList = mRootFolder->getFilesRecursive(GAME, false, false);
}
else {
gameList = ViewController::getInstance()
->getGamelistView(mRootFolder->getSystem())
.get()
->getCursor()
->getParent()
->getChildrenListToDisplay();
}
}
if (gameList.size() > 0 && gameList.front()->getParent()->getOnlyFoldersFlag())

View file

@ -128,7 +128,7 @@ public:
SystemData* getNext() const;
SystemData* getPrev() const;
static SystemData* getRandomSystem(const SystemData* currentSystem);
FileData* getRandomGame(const FileData* currentGame = nullptr);
FileData* getRandomGame(const FileData* currentGame = nullptr, bool gameSelectorMode = false);
FileData* getPlaceholder() { return mPlaceholder; }
void sortSystem(bool reloadGamelist = true, bool jumpToFirstRow = false);

View file

@ -34,7 +34,9 @@ public:
if (mGameSelection == GameSelection::RANDOM) {
for (int i = 0; i < mGameCount; ++i) {
FileData* randomGame {mSystem->getRandomGame()};
if (mSystem->getRootFolder()->getGameCount().first == 0)
break;
FileData* randomGame {mSystem->getRandomGame(nullptr, true)};
if (randomGame != nullptr)
mGames.emplace_back(randomGame);
}