From cf850598eb518c08a194a2d3843b1fb5d4a77e26 Mon Sep 17 00:00:00 2001 From: Elad <18193363+elad335@users.noreply.github.com> Date: Wed, 27 Nov 2024 21:40:28 +0200 Subject: [PATCH] System.cpp: Do not hold on fs::dir handle --- rpcs3/Emu/System.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index f050456c56..a4dbf084a5 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -4001,14 +4001,20 @@ u32 Emulator::AddGamesFromDir(const std::string& path) games_added++; } - fs::dir fs_dir{path}; + std::vector entries; - auto path_it = fs_dir.begin(); + for (auto&& dir_entry : fs::dir(path)) + { + // Prefetch entries, it is unsafe to keep fs::dir for a long time or for many operations + entries.emplace_back(std::move(dir_entry)); + } + + auto path_it = entries.begin(); qt_events_aware_op(0, [&]() { // search direct subdirectories, that way we can drop one folder containing all games - for (; path_it != fs_dir.end(); ++path_it) + for (; path_it != entries.end(); ++path_it) { auto dir_entry = std::move(*path_it);