From b29758a5e7bda37cbdaedd4bf757218505ba2759 Mon Sep 17 00:00:00 2001 From: Nicholas Bly <73457207+NicholasBly@users.noreply.github.com> Date: Thu, 24 Sep 2026 23:45:54 -0400 Subject: [PATCH 1/3] Add a restart option to the exit prompt Relaunches the current executable with its own command line, so base game and Retro Rewind each restart into themselves. The relaunch happens after the controllers are released and window placement is flushed, so the new instance reads the saved state. Windows only; the button is hidden elsewhere. --- runtime/include/aurora_events.h | 4 +++- runtime/include/platform/host_platform.h | 3 +++ runtime/src/platform/host_platform.cpp | 24 ++++++++++++++++++++++++ runtime/src/settings_overlay.cpp | 4 ++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/runtime/include/aurora_events.h b/runtime/include/aurora_events.h index e10c151aa..3a7df85b5 100644 --- a/runtime/include/aurora_events.h +++ b/runtime/include/aurora_events.h @@ -2,6 +2,7 @@ #include "settings_overlay.h" #include "runtime_config.h" +#include "platform/host_platform.h" #include #include @@ -59,9 +60,10 @@ inline void Flush(bool force = false) { // fiber re-enters runtime teardown and can fault while the fiber machinery is // still active. A window close is an intentional successful exit, so end the // process directly and do not run the crash/atexit paths. -[[noreturn]] inline void ExitForAuroraWindowClose() noexcept { +[[noreturn]] inline void ExitForAuroraWindowClose(bool relaunch = false) noexcept { settings_overlay::ReleaseControllers(); WindowPlacementPersistence::Flush(true); + if (relaunch) RuntimePlatform::RelaunchSelf(); #if defined(_WIN32) ::ExitProcess(0); #else diff --git a/runtime/include/platform/host_platform.h b/runtime/include/platform/host_platform.h index 1fd961e01..9ea1872cf 100644 --- a/runtime/include/platform/host_platform.h +++ b/runtime/include/platform/host_platform.h @@ -23,4 +23,7 @@ std::filesystem::path LogDirectory(std::string_view applicationName); uint64_t CurrentProcessId() noexcept; +// Starts a new instance with the current command line. False if unsupported or it fails. +bool RelaunchSelf() noexcept; + } // namespace RuntimePlatform diff --git a/runtime/src/platform/host_platform.cpp b/runtime/src/platform/host_platform.cpp index c0caa95a5..1cd4752ce 100644 --- a/runtime/src/platform/host_platform.cpp +++ b/runtime/src/platform/host_platform.cpp @@ -82,4 +82,28 @@ uint64_t CurrentProcessId() noexcept { #endif } +bool RelaunchSelf() noexcept { +#if defined(_WIN32) + std::wstring path(32768, L'\0'); + const DWORD length = GetModuleFileNameW(nullptr, path.data(), static_cast(path.size())); + if (length == 0 || length >= path.size()) { + return false; + } + path.resize(length); + std::wstring commandLine = GetCommandLineW(); + STARTUPINFOW startup{}; + startup.cb = sizeof(startup); + PROCESS_INFORMATION process{}; + if (!CreateProcessW(path.c_str(), commandLine.data(), nullptr, nullptr, FALSE, 0, nullptr, nullptr, + &startup, &process)) { + return false; + } + CloseHandle(process.hThread); + CloseHandle(process.hProcess); + return true; +#else + return false; +#endif +} + } // namespace RuntimePlatform diff --git a/runtime/src/settings_overlay.cpp b/runtime/src/settings_overlay.cpp index 616d141d8..a5d330bd6 100644 --- a/runtime/src/settings_overlay.cpp +++ b/runtime/src/settings_overlay.cpp @@ -1206,6 +1206,10 @@ void DrawExitPrompt() { ImGui::TextUnformatted("Quit the game?"); if (ImGui::Button("Exit", ImVec2(120.0f, 0.0f))) ExitForAuroraWindowClose(); ImGui::SameLine(); +#if defined(_WIN32) + if (ImGui::Button("Restart", ImVec2(120.0f, 0.0f))) ExitForAuroraWindowClose(true); + ImGui::SameLine(); +#endif if (ImGui::Button("Cancel", ImVec2(120.0f, 0.0f))) g_exitPromptOpen = false; if (!g_exitPromptOpen) ImGui::CloseCurrentPopup(); ImGui::EndPopup(); From ac2dded62c8f191106b45f6b23507fc1a6aaafd9 Mon Sep 17 00:00:00 2001 From: Nicholas Bly <73457207+NicholasBly@users.noreply.github.com> Date: Fri, 25 Sep 2026 14:38:03 -0400 Subject: [PATCH 2/3] Keep running if a restart fails, and support Linux and macOS Restart now returns instead of exiting when the new instance cannot be started, and the prompt says so. ExitForAuroraWindowClose is back to its original signature. On Linux and macOS the relaunch uses posix_spawn. The runtime rejects any command-line arguments, so the new instance is started with only its own path. Inherited descriptors are marked close-on-exec first: unlike Windows, where CreateProcess is told not to inherit handles, a spawned process otherwise keeps the old instance's sockets and devices open. --- runtime/include/aurora_events.h | 9 ++++-- runtime/include/platform/host_platform.h | 2 +- runtime/src/platform/host_platform.cpp | 39 +++++++++++++++++++++++- runtime/src/settings_overlay.cpp | 14 ++++++--- 4 files changed, 56 insertions(+), 8 deletions(-) diff --git a/runtime/include/aurora_events.h b/runtime/include/aurora_events.h index 3a7df85b5..0f933d8de 100644 --- a/runtime/include/aurora_events.h +++ b/runtime/include/aurora_events.h @@ -60,10 +60,9 @@ inline void Flush(bool force = false) { // fiber re-enters runtime teardown and can fault while the fiber machinery is // still active. A window close is an intentional successful exit, so end the // process directly and do not run the crash/atexit paths. -[[noreturn]] inline void ExitForAuroraWindowClose(bool relaunch = false) noexcept { +[[noreturn]] inline void ExitForAuroraWindowClose() noexcept { settings_overlay::ReleaseControllers(); WindowPlacementPersistence::Flush(true); - if (relaunch) RuntimePlatform::RelaunchSelf(); #if defined(_WIN32) ::ExitProcess(0); #else @@ -71,6 +70,12 @@ inline void Flush(bool force = false) { #endif } +// Returns only if the new instance could not be started, leaving this one running. +inline void RestartForAuroraWindowClose() noexcept { + WindowPlacementPersistence::Flush(true); + if (RuntimePlatform::RelaunchSelf()) ExitForAuroraWindowClose(); +} + // Update cached Aurora window/framebuffer dimensions based on pending events. inline void ProcessAuroraEvents(const AuroraEvent* events) { if (!events) { diff --git a/runtime/include/platform/host_platform.h b/runtime/include/platform/host_platform.h index 9ea1872cf..9be073b40 100644 --- a/runtime/include/platform/host_platform.h +++ b/runtime/include/platform/host_platform.h @@ -23,7 +23,7 @@ std::filesystem::path LogDirectory(std::string_view applicationName); uint64_t CurrentProcessId() noexcept; -// Starts a new instance with the current command line. False if unsupported or it fails. +// Starts a new instance of this executable. False if it could not be started. bool RelaunchSelf() noexcept; } // namespace RuntimePlatform diff --git a/runtime/src/platform/host_platform.cpp b/runtime/src/platform/host_platform.cpp index 1cd4752ce..2a4d63369 100644 --- a/runtime/src/platform/host_platform.cpp +++ b/runtime/src/platform/host_platform.cpp @@ -9,10 +9,18 @@ #include #include #else +#include +#include +#include #include #endif +#if !defined(_WIN32) && !defined(__APPLE__) +#include +#endif + #if defined(__APPLE__) +#include #include #include #endif @@ -102,7 +110,36 @@ bool RelaunchSelf() noexcept { CloseHandle(process.hProcess); return true; #else - return false; + char path[PATH_MAX]; + // Mark inherited descriptors close-on-exec, or the new instance keeps this one's sockets and devices open. +#if defined(__APPLE__) + uint32_t size = sizeof(path); + if (_NSGetExecutablePath(path, &size) != 0) { + return false; + } + char** const env = *_NSGetEnviron(); + for (int fd = 3, max = getdtablesize(); fd < max; ++fd) { + fcntl(fd, F_SETFD, FD_CLOEXEC); + } +#else + const ssize_t length = readlink("/proc/self/exe", path, sizeof(path) - 1); + if (length <= 0) { + return false; + } + path[length] = '\0'; + char** const env = environ; + if (DIR* dir = opendir("/proc/self/fd")) { + while (const dirent* entry = readdir(dir)) { + if (const int fd = std::atoi(entry->d_name); fd > 2 && fd != dirfd(dir)) { + fcntl(fd, F_SETFD, FD_CLOEXEC); + } + } + closedir(dir); + } +#endif + char* const argv[] = {path, nullptr}; + pid_t pid = 0; + return posix_spawn(&pid, path, nullptr, nullptr, argv, env) == 0; #endif } diff --git a/runtime/src/settings_overlay.cpp b/runtime/src/settings_overlay.cpp index a5d330bd6..640eb8b13 100644 --- a/runtime/src/settings_overlay.cpp +++ b/runtime/src/settings_overlay.cpp @@ -1202,14 +1202,20 @@ void DrawStartupScreen() { void DrawExitPrompt() { constexpr const char* kTitle = "Exit"; if (g_exitPromptOpen && !ImGui::IsPopupOpen(kTitle)) ImGui::OpenPopup(kTitle); - if (!ImGui::BeginPopupModal(kTitle, &g_exitPromptOpen, ImGuiWindowFlags_AlwaysAutoResize)) return; + static bool restartFailed = false; + if (!ImGui::BeginPopupModal(kTitle, &g_exitPromptOpen, ImGuiWindowFlags_AlwaysAutoResize)) { + restartFailed = false; + return; + } ImGui::TextUnformatted("Quit the game?"); + if (restartFailed) ImGui::TextDisabled("Could not restart."); if (ImGui::Button("Exit", ImVec2(120.0f, 0.0f))) ExitForAuroraWindowClose(); ImGui::SameLine(); -#if defined(_WIN32) - if (ImGui::Button("Restart", ImVec2(120.0f, 0.0f))) ExitForAuroraWindowClose(true); + if (ImGui::Button("Restart", ImVec2(120.0f, 0.0f))) { + RestartForAuroraWindowClose(); + restartFailed = true; + } ImGui::SameLine(); -#endif if (ImGui::Button("Cancel", ImVec2(120.0f, 0.0f))) g_exitPromptOpen = false; if (!g_exitPromptOpen) ImGui::CloseCurrentPopup(); ImGui::EndPopup(); From e93739b2b7bd1f8a0c4cd579322b657f74b9ab20 Mon Sep 17 00:00:00 2001 From: Nicholas Bly <73457207+NicholasBly@users.noreply.github.com> Date: Fri, 25 Sep 2026 16:47:54 -0400 Subject: [PATCH 3/3] Stop rumble before relaunching, and size the macOS path dynamically Restart now stops rumble before the new instance is spawned and leaves the LED alone. The new instance sets its own LED, so resetting it here was both unnecessary and a race: this process could turn it off after the new one had turned it on. A failed relaunch therefore leaves the LED as it was, with only rumble stopped, which the game re-issues on its next event. ReleaseControllers takes resetLeds, and its report-flush delay now runs whenever a controller is connected, not only when an LED was written. On macOS, _NSGetExecutablePath is asked for the required size first rather than failing when the path exceeds PATH_MAX, matching ExecutableDirectory. --- runtime/include/aurora_events.h | 15 ++++++++++----- runtime/include/settings_overlay.h | 2 +- runtime/src/platform/host_platform.cpp | 19 ++++++++++++------- runtime/src/settings_overlay.cpp | 4 ++-- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/runtime/include/aurora_events.h b/runtime/include/aurora_events.h index 0f933d8de..b54d81314 100644 --- a/runtime/include/aurora_events.h +++ b/runtime/include/aurora_events.h @@ -60,9 +60,7 @@ inline void Flush(bool force = false) { // fiber re-enters runtime teardown and can fault while the fiber machinery is // still active. A window close is an intentional successful exit, so end the // process directly and do not run the crash/atexit paths. -[[noreturn]] inline void ExitForAuroraWindowClose() noexcept { - settings_overlay::ReleaseControllers(); - WindowPlacementPersistence::Flush(true); +[[noreturn]] inline void ExitAuroraProcess() noexcept { #if defined(_WIN32) ::ExitProcess(0); #else @@ -70,10 +68,17 @@ inline void Flush(bool force = false) { #endif } -// Returns only if the new instance could not be started, leaving this one running. +[[noreturn]] inline void ExitForAuroraWindowClose() noexcept { + settings_overlay::ReleaseControllers(); + WindowPlacementPersistence::Flush(true); + ExitAuroraProcess(); +} + +// Returns only if the new instance could not be started; the LED is left for the new instance to set. inline void RestartForAuroraWindowClose() noexcept { WindowPlacementPersistence::Flush(true); - if (RuntimePlatform::RelaunchSelf()) ExitForAuroraWindowClose(); + settings_overlay::ReleaseControllers(false); + if (RuntimePlatform::RelaunchSelf()) ExitAuroraProcess(); } // Update cached Aurora window/framebuffer dimensions based on pending events. diff --git a/runtime/include/settings_overlay.h b/runtime/include/settings_overlay.h index 631eb3a6a..6aa3ace17 100644 --- a/runtime/include/settings_overlay.h +++ b/runtime/include/settings_overlay.h @@ -13,5 +13,5 @@ bool StartupScreenVisible() noexcept; void NotifyStrapInputAccepted() noexcept; void AdvancePresentedFrame() noexcept; // Put host controllers back to a neutral state before the process ends. -void ReleaseControllers() noexcept; +void ReleaseControllers(bool resetLeds = true) noexcept; } // namespace settings_overlay diff --git a/runtime/src/platform/host_platform.cpp b/runtime/src/platform/host_platform.cpp index 2a4d63369..20d48b046 100644 --- a/runtime/src/platform/host_platform.cpp +++ b/runtime/src/platform/host_platform.cpp @@ -110,11 +110,15 @@ bool RelaunchSelf() noexcept { CloseHandle(process.hProcess); return true; #else - char path[PATH_MAX]; + std::string path; // Mark inherited descriptors close-on-exec, or the new instance keeps this one's sockets and devices open. #if defined(__APPLE__) - uint32_t size = sizeof(path); - if (_NSGetExecutablePath(path, &size) != 0) { + uint32_t size = 0; + if (_NSGetExecutablePath(nullptr, &size) != -1 || size == 0) { + return false; + } + path.resize(size); + if (_NSGetExecutablePath(path.data(), &size) != 0) { return false; } char** const env = *_NSGetEnviron(); @@ -122,11 +126,12 @@ bool RelaunchSelf() noexcept { fcntl(fd, F_SETFD, FD_CLOEXEC); } #else - const ssize_t length = readlink("/proc/self/exe", path, sizeof(path) - 1); + path.resize(PATH_MAX); + const ssize_t length = readlink("/proc/self/exe", path.data(), path.size() - 1); if (length <= 0) { return false; } - path[length] = '\0'; + path.resize(static_cast(length)); char** const env = environ; if (DIR* dir = opendir("/proc/self/fd")) { while (const dirent* entry = readdir(dir)) { @@ -137,9 +142,9 @@ bool RelaunchSelf() noexcept { closedir(dir); } #endif - char* const argv[] = {path, nullptr}; + char* const argv[] = {path.data(), nullptr}; pid_t pid = 0; - return posix_spawn(&pid, path, nullptr, nullptr, argv, env) == 0; + return posix_spawn(&pid, path.c_str(), nullptr, nullptr, argv, env) == 0; #endif } diff --git a/runtime/src/settings_overlay.cpp b/runtime/src/settings_overlay.cpp index 640eb8b13..39606379b 100644 --- a/runtime/src/settings_overlay.cpp +++ b/runtime/src/settings_overlay.cpp @@ -1433,7 +1433,7 @@ void HandleEvents(const AuroraEvent* events) noexcept { } } -void ReleaseControllers() noexcept { +void ReleaseControllers(bool resetLeds) noexcept { // Aurora drives the LED white on first PADRead and never clears it, and the // exit paths terminate the process outright, so do it here. bool queued = false; @@ -1441,7 +1441,7 @@ void ReleaseControllers() noexcept { const s32 index = PADGetIndexForPort(port); if (index < 0) continue; if (SDL_Gamepad* pad = PADGetSDLGamepadForIndex(static_cast(index))) { - SDL_SetGamepadLED(pad, 0, 0, 0); + if (resetLeds) SDL_SetGamepadLED(pad, 0, 0, 0); queued = true; } }