Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI state is not saved correctly if not using the internal Quit menu item #1832

Open
1 of 5 tasks
sigmate opened this issue Jan 5, 2025 · 2 comments
Open
1 of 5 tasks

Comments

@sigmate
Copy link

sigmate commented Jan 5, 2025

Describe the bug

Running macOS, if I use Cmd+Q, the OS menu bar "Quit" item or any system way tell PCSX-Redux to exit, then all my currently opened windows won't be remembered at next launch. If I want to avoid the issue, I must click the internal ImGui menu item in the main window.

Expected behavior

The GUI state should be saved regardless of the way which is used to exit the app. Especially in a PSX development scenario where PCSX has to be started a lot and where it's easier to quit via a keyboard shortcut.

Steps to reproduce the bug

  1. Start PCSX
  2. Open, e.g. the CPU registers window
  3. Hit Cmd+Q
  4. Re-start PCSX
  5. CPU registers window does not re-open
  6. Open CPU registers window
  7. Click the internal "Quit" menu item in the main window
  8. Re-start PCSX
  9. The CPU registers window re-opens

Operating System

macOS Sequoia 15.2

PCSX-Redux version

Version: bc029a7
Build: 65
Changeset: bc029a7
Date & time: 2024-10-24 07:29:35

CPU model

Apple Silicon M2 MAX

GPU model & Drivers

Apple Silicon M2 MAX

BIOS version

SCPH5502 - SCPH5552 (EU)

Options

  • Dynarec CPU
  • 8MB
  • OpenGL GPU
  • Fastboot
  • Debugger

Iso checks

No response

Logs

Glfw Error 65548: Cocoa: Regular windows do not have icons on macOS
Loading memory card /Users/xxx/.config/pcsx-redux/memcard1.mcd
Loading memory card /Users/xxx/.config/pcsx-redux/memcard2.mcd
Warning: OpenGL error reporting disabled. See About dialog for more information.
PCSX-Redux booting
Copyright (C) 2019-2024 PCSX-Redux authors
CPU type: Interpreted
Loaded BIOS: /Users/xxx/Development/ps1usb/ps1transfer/bios.bin
Known BIOS detected: SCPH-5502 - SCPH-5552 (EU) (d786f0b9)

Additional information

No response

@nicolasnoble
Copy link
Member

Hmmmmm, this feels like a GLFW bug. Basically, here's how this is supposed to work:

In gui.cc, we periodically ask glfw if we need to quit, usually caused by a window close event:

if (glfwWindowShouldClose(m_window)) g_system->quit();

The quit function triggers a Quitting event:

m_eventBus->signal(Events::Quitting{});

Which is listened to by the gui itself:

m_listener.listen<Events::Quitting>([this](const auto& event) { saveCfg(); });

And it finally saves the imgui context out:

j["imgui"] = ImGui::SaveIniSettingsToMemory(nullptr);

I think what you're describing is that somehow, this doesn't properly work in MacOS: https://www.glfw.org/docs/3.3/window_guide.html#window_close

Unfortunately, I don't have a Mac machine myself to test or debug this out.

@sigmate
Copy link
Author

sigmate commented Jan 5, 2025

Thanks for your feedback! I was able to fork and build on macOS to try to find the issue. It is due to GLFW forcing all windows to close when the app will terminate. So when saveCfg() is called in reaction to your quitting event, all secondary windows are already closed and the persisted GUI state will be wrong in that aspect.

However, there seems to be some redundancy between

if (io.WantSaveIniSettings) {

and

m_listener.listen<Events::Quitting>([this](const auto& event) { saveCfg(); });

The first one seems to handle config saving pretty well. For testing, I just commented out saveCfg() in the event listener, just left the one in startFrame() and this solved the issue for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants