From 3f66297593b540e586545e4020d08d1609f0e162 Mon Sep 17 00:00:00 2001 From: Antonino Di Guardo <64427768+digant73@users.noreply.github.com> Date: Sun, 29 Sep 2024 02:11:27 +0200 Subject: [PATCH] Fix crash on VFS Tool (#16146) --- rpcs3/Emu/VFS.cpp | 16 +++++++++++++++- rpcs3/rpcs3qt/main_window.cpp | 8 ++++---- rpcs3/rpcs3qt/main_window.h | 2 +- rpcs3/rpcs3qt/main_window.ui | 4 ++-- rpcs3/rpcs3qt/vfs_tool_dialog.cpp | 7 +++++++ 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/rpcs3/Emu/VFS.cpp b/rpcs3/Emu/VFS.cpp index 3f73dbbcff..800a7f9ff6 100644 --- a/rpcs3/Emu/VFS.cpp +++ b/rpcs3/Emu/VFS.cpp @@ -43,7 +43,7 @@ bool vfs::mount(std::string_view vpath, std::string_view path, bool is_dir) return false; } - // Workaround + // Initialize vfs_manager if not yet initialized (e.g. g_fxo->reset() was previously invoked) g_fxo->need(); auto& table = g_fxo->get(); @@ -196,6 +196,13 @@ bool vfs::unmount(std::string_view vpath) std::string vfs::get(std::string_view vpath, std::vector* out_dir, std::string* out_path) { + // Just to make the code more robust. + // It should never happen because we take care to initialize Emu (and so also vfs_manager) with Emu.Init() before this function is invoked + if (!g_fxo->is_init()) + { + fmt::throw_exception("vfs_manager not initialized"); + } + auto& table = g_fxo->get(); reader_lock lock(table.mutex); @@ -372,6 +379,13 @@ using char2 = char8_t; std::string vfs::retrieve(std::string_view path, const vfs_directory* node, std::vector* mount_path) { + // Just to make the code more robust. + // It should never happen because we take care to initialize Emu (and so also vfs_manager) with Emu.Init() before this function is invoked + if (!g_fxo->is_init()) + { + fmt::throw_exception("vfs_manager not initialized"); + } + auto& table = g_fxo->get(); if (!node) diff --git a/rpcs3/rpcs3qt/main_window.cpp b/rpcs3/rpcs3qt/main_window.cpp index e13603e72f..2eb5d68b32 100644 --- a/rpcs3/rpcs3qt/main_window.cpp +++ b/rpcs3/rpcs3qt/main_window.cpp @@ -1986,7 +1986,7 @@ void main_window::OnEmuStop() ui->removeHDD1CachesAct->setEnabled(true); ui->removeAllCachesAct->setEnabled(true); ui->removeSavestatesAct->setEnabled(true); - ui->cleanupGameListAct->setEnabled(true); + ui->cleanUpGameListAct->setEnabled(true); ui->actionManage_Users->setEnabled(true); ui->confCamerasAct->setEnabled(true); @@ -2039,7 +2039,7 @@ void main_window::OnEmuReady() const ui->removeHDD1CachesAct->setEnabled(false); ui->removeAllCachesAct->setEnabled(false); ui->removeSavestatesAct->setEnabled(false); - ui->cleanupGameListAct->setEnabled(false); + ui->cleanUpGameListAct->setEnabled(false); } void main_window::EnableMenus(bool enabled) const @@ -2694,7 +2694,7 @@ void main_window::CreateConnects() connect(ui->removeHDD1CachesAct, &QAction::triggered, this, &main_window::RemoveHDD1Caches); connect(ui->removeAllCachesAct, &QAction::triggered, this, &main_window::RemoveAllCaches); connect(ui->removeSavestatesAct, &QAction::triggered, this, &main_window::RemoveSavestates); - connect(ui->cleanupGameListAct, &QAction::triggered, this, &main_window::CleanupGameList); + connect(ui->cleanUpGameListAct, &QAction::triggered, this, &main_window::CleanUpGameList); connect(ui->removeFirmwareCacheAct, &QAction::triggered, this, &main_window::RemoveFirmwareCache); connect(ui->createFirmwareCacheAct, &QAction::triggered, this, &main_window::CreateFirmwareCache); @@ -3604,7 +3604,7 @@ void main_window::RemoveSavestates() } } -void main_window::CleanupGameList() +void main_window::CleanUpGameList() { if (QMessageBox::question(this, tr("Confirm Removal"), tr("Remove invalid game paths from game list?\n" "Undetectable games (zombies) as well as corrupted games will be removed from the game list file (games.yml)")) != QMessageBox::Yes) diff --git a/rpcs3/rpcs3qt/main_window.h b/rpcs3/rpcs3qt/main_window.h index de6ad8ab0d..fa493549c8 100644 --- a/rpcs3/rpcs3qt/main_window.h +++ b/rpcs3/rpcs3qt/main_window.h @@ -132,7 +132,7 @@ private Q_SLOTS: void RemoveHDD1Caches(); void RemoveAllCaches(); void RemoveSavestates(); - void CleanupGameList(); + void CleanUpGameList(); void RemoveFirmwareCache(); void CreateFirmwareCache(); diff --git a/rpcs3/rpcs3qt/main_window.ui b/rpcs3/rpcs3qt/main_window.ui index daa567540b..a05e531dc6 100644 --- a/rpcs3/rpcs3qt/main_window.ui +++ b/rpcs3/rpcs3qt/main_window.ui @@ -193,7 +193,7 @@ - + @@ -1166,7 +1166,7 @@ Remove Savestates - + Clean up Game List diff --git a/rpcs3/rpcs3qt/vfs_tool_dialog.cpp b/rpcs3/rpcs3qt/vfs_tool_dialog.cpp index 91d01b5684..71cc0a3374 100644 --- a/rpcs3/rpcs3qt/vfs_tool_dialog.cpp +++ b/rpcs3/rpcs3qt/vfs_tool_dialog.cpp @@ -2,6 +2,7 @@ #include "vfs_tool_dialog.h" #include "ui_vfs_tool_dialog.h" #include "Emu/VFS.h" +#include "Emu/System.h" vfs_tool_dialog::vfs_tool_dialog(QWidget *parent) : QDialog(parent) @@ -22,6 +23,12 @@ vfs_tool_dialog::~vfs_tool_dialog() void vfs_tool_dialog::handle_vfs_path(const QString& path) { + // Initialize Emu if not yet initialized (e.g. Emu.Kill() was previously invoked) before using some of the following vfs:: functions (e.g. vfs::get()) + if (Emu.IsStopped()) + { + Emu.Init(); + } + const std::string spath = path.toStdString(); const std::string vfs_get_path = vfs::get(spath); const std::string vfs_retrieve_path = vfs::retrieve(spath);