Skip to content

Commit

Permalink
RMG: fix 'open_rom(): not a valid ROM image' error showing up sometimes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosalie241 committed Aug 27, 2023
1 parent 0e2a1ba commit 9e827f9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
22 changes: 14 additions & 8 deletions Source/RMG/UserInterface/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ MainWindow::~MainWindow()
{
}

bool MainWindow::Init(QApplication* app, bool showUI)
bool MainWindow::Init(QApplication* app, bool showUI, bool launchROM)
{
if (!CoreInit())
{
Expand All @@ -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);

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -156,7 +156,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
QMainWindow::closeEvent(event);
}

void MainWindow::initializeUI(void)
void MainWindow::initializeUI(bool launchROM)
{
this->setupUi(this);

Expand All @@ -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);
Expand Down Expand Up @@ -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();

Expand All @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions Source/RMG/UserInterface/MainWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions Source/RMG/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 9e827f9

Please sign in to comment.