diff --git a/src/window_gamelist.cpp b/src/window_gamelist.cpp index 6fd0bb17d5..8949240d2c 100644 --- a/src/window_gamelist.cpp +++ b/src/window_gamelist.cpp @@ -37,10 +37,21 @@ bool Window_GameList::Refresh(FilesystemView filesystem_base, bool show_dotdot) this->show_dotdot = show_dotdot; - auto files = base_fs.ListDirectory(); +#ifndef USE_CUSTOM_FILEBUF + // Calling "Create" while iterating over the directory list appears to corrupt + // the file entries probably because of a reallocation due to caching new entries. + // Create a copy of the entries instead to workaround this issue. + DirectoryTree::DirectoryListType files = *base_fs.ListDirectory(); +#else + DirectoryTree::DirectoryListType* files = base_fs.ListDirectory(); +#endif // Find valid game diectories +#ifndef USE_CUSTOM_FILEBUF + for (auto& dir : files) { +#else for (auto& dir : *files) { +#endif assert(!dir.second.name.empty() && "VFS BUG: Empty filename in the folder"); #ifdef EMSCRIPTEN @@ -57,7 +68,7 @@ bool Window_GameList::Refresh(FilesystemView filesystem_base, bool show_dotdot) // The type is only determined on platforms with fast file IO (Windows and UNIX systems) // A platform is considered "fast" when it does not require our custom IO buffer #ifndef USE_CUSTOM_FILEBUF - auto fs = base_fs.Create(dir.second.name); + FilesystemView fs = base_fs.Create(dir.second.name); game_entries.push_back({ dir.second.name, FileFinder::GetProjectType(fs) }); #else game_entries.push_back({ dir.second.name, FileFinder::ProjectType::Unknown }); @@ -65,7 +76,7 @@ bool Window_GameList::Refresh(FilesystemView filesystem_base, bool show_dotdot) } } else if (dir.second.type == DirectoryTree::FileType::Directory) { #ifndef USE_CUSTOM_FILEBUF - auto fs = base_fs.Create(dir.second.name); + FilesystemView fs = base_fs.Create(dir.second.name); game_entries.push_back({ dir.second.name, FileFinder::GetProjectType(fs) }); #else game_entries.push_back({ dir.second.name, FileFinder::ProjectType::Unknown });