From 9e827f97f2bfe9a1471fdf466bbb5cf9e4ccfb0a Mon Sep 17 00:00:00 2001 From: Rosalie Wanders Date: Sun, 27 Aug 2023 19:49:48 +0200 Subject: [PATCH] RMG: fix 'open_rom(): not a valid ROM image' error showing up sometimes --- Source/RMG/UserInterface/MainWindow.cpp | 22 ++++++++++++++-------- Source/RMG/UserInterface/MainWindow.hpp | 6 +++--- Source/RMG/main.cpp | 6 ++++-- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Source/RMG/UserInterface/MainWindow.cpp b/Source/RMG/UserInterface/MainWindow.cpp index 59a5895e..e5e6bd5b 100644 --- a/Source/RMG/UserInterface/MainWindow.cpp +++ b/Source/RMG/UserInterface/MainWindow.cpp @@ -49,7 +49,7 @@ MainWindow::~MainWindow() { } -bool MainWindow::Init(QApplication* app, bool showUI) +bool MainWindow::Init(QApplication* app, bool showUI, bool launchROM) { if (!CoreInit()) { @@ -64,7 +64,7 @@ bool MainWindow::Init(QApplication* app, bool showUI) this->configureTheme(app); - this->initializeUI(); + this->initializeUI(launchROM); this->initializeActions(); this->configureUI(app, showUI); @@ -117,8 +117,8 @@ void MainWindow::OpenROM(QString file, QString disk, bool fullscreen, bool quitA // if we just ensure the UI is in an emulation // state, then the transition will be smoother this->updateUI(true, false); - - this->launchEmulationThread(file, disk); + + this->launchEmulationThread(file, disk, true); } void MainWindow::closeEvent(QCloseEvent *event) @@ -156,7 +156,7 @@ void MainWindow::closeEvent(QCloseEvent *event) QMainWindow::closeEvent(event); } -void MainWindow::initializeUI(void) +void MainWindow::initializeUI(bool launchROM) { this->setupUi(this); @@ -168,7 +168,13 @@ void MainWindow::initializeUI(void) this->ui_StatusBar_Label = new QLabel(this); this->ui_StatusBar_RenderModeLabel = new QLabel(this); - this->ui_Widget_RomBrowser->RefreshRomList(); + // only start refreshing the ROM browser + // when RMG isn't launched with a ROM + // specified on the commandline + if (!launchROM) + { + this->ui_Widget_RomBrowser->RefreshRomList(); + } connect(this->ui_Widget_RomBrowser, &Widget::RomBrowserWidget::PlayGame, this, &MainWindow::on_RomBrowser_PlayGame); @@ -521,7 +527,7 @@ void MainWindow::connectEmulationThreadSignals(void) Qt::BlockingQueuedConnection); } -void MainWindow::launchEmulationThread(QString cartRom, QString diskRom) +void MainWindow::launchEmulationThread(QString cartRom, QString diskRom, bool onStartup) { CoreSettingsSave(); @@ -535,7 +541,7 @@ void MainWindow::launchEmulationThread(QString cartRom, QString diskRom) } } - this->ui_RefreshRomListAfterEmulation = this->ui_Widget_RomBrowser->IsRefreshingRomList(); + this->ui_RefreshRomListAfterEmulation = onStartup || this->ui_Widget_RomBrowser->IsRefreshingRomList(); if (this->ui_RefreshRomListAfterEmulation) { this->ui_Widget_RomBrowser->StopRefreshRomList(); diff --git a/Source/RMG/UserInterface/MainWindow.hpp b/Source/RMG/UserInterface/MainWindow.hpp index 636f2dfb..63561b6b 100644 --- a/Source/RMG/UserInterface/MainWindow.hpp +++ b/Source/RMG/UserInterface/MainWindow.hpp @@ -48,7 +48,7 @@ class MainWindow : public QMainWindow, private Ui::MainWindow MainWindow(void); ~MainWindow(void); - bool Init(QApplication* app, bool showUI); + bool Init(QApplication* app, bool showUI, bool launchROM); void OpenROM(QString file, QString disk, bool fullscreen, bool quitAfterEmulation); private: @@ -113,7 +113,7 @@ class MainWindow : public QMainWindow, private Ui::MainWindow void closeEvent(QCloseEvent *) Q_DECL_OVERRIDE; - void initializeUI(); + void initializeUI(bool launchROM); void configureUI(QApplication* app, bool showUI); void configureTheme(QApplication* app); @@ -127,7 +127,7 @@ class MainWindow : public QMainWindow, private Ui::MainWindow void initializeEmulationThread(void); void connectEmulationThreadSignals(void); - void launchEmulationThread(QString cartRom, QString diskRom = ""); + void launchEmulationThread(QString cartRom, QString diskRom = "", bool onStartup = false); QString getSaveStateSlotDateTimeText(QAction* action); QString getSaveStateSlotText(QAction* action, int slot); diff --git a/Source/RMG/main.cpp b/Source/RMG/main.cpp index 53c0ed26..690896b2 100644 --- a/Source/RMG/main.cpp +++ b/Source/RMG/main.cpp @@ -209,13 +209,15 @@ int main(int argc, char **argv) // print debug callbacks to stdout if needed CoreSetPrintDebugCallback(parser.isSet(debugMessagesOption)); + // specified ROM path to launch + QStringList args = parser.positionalArguments(); + // initialize window - if (!window.Init(&app, !parser.isSet(noGuiOption))) + if (!window.Init(&app, !parser.isSet(noGuiOption), !args.empty())) { return 1; } - QStringList args = parser.positionalArguments(); if (!args.empty()) { window.OpenROM(args.at(0), parser.value(diskOption), parser.isSet(fullscreenOption), parser.isSet(quitAfterEmulationOption));