diff --git a/src/duckstation-sdl/d3d11_host_display.cpp b/src/duckstation-sdl/d3d11_host_display.cpp index 3398b9ed9..4c7c8db62 100644 --- a/src/duckstation-sdl/d3d11_host_display.cpp +++ b/src/duckstation-sdl/d3d11_host_display.cpp @@ -381,6 +381,7 @@ void D3D11HostDisplay::Render() RenderDisplay(); + ImGui::Render(); ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); if (!m_vsync && m_allow_tearing_supported) diff --git a/src/duckstation-sdl/opengl_host_display.cpp b/src/duckstation-sdl/opengl_host_display.cpp index 50b2c0fa6..df421b4b6 100644 --- a/src/duckstation-sdl/opengl_host_display.cpp +++ b/src/duckstation-sdl/opengl_host_display.cpp @@ -355,6 +355,7 @@ void OpenGLHostDisplay::Render() RenderDisplay(); + ImGui::Render(); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); SDL_GL_SwapWindow(m_window); diff --git a/src/duckstation-sdl/sdl_host_interface.cpp b/src/duckstation-sdl/sdl_host_interface.cpp index 94e369753..f5b216b6a 100644 --- a/src/duckstation-sdl/sdl_host_interface.cpp +++ b/src/duckstation-sdl/sdl_host_interface.cpp @@ -27,7 +27,7 @@ Log_SetChannel(SDLHostInterface); SDLHostInterface::SDLHostInterface() { - m_update_settings_event_id = SDL_RegisterEvents(1); + m_run_later_event_id = SDL_RegisterEvents(1); } SDLHostInterface::~SDLHostInterface() @@ -198,20 +198,22 @@ void SDLHostInterface::OnControllerTypeChanged(u32 slot) g_sdl_controller_interface.SetDefaultBindings(); } -void SDLHostInterface::SaveSettings() -{ - SDLSettingsInterface si(GetSettingsFileName().c_str()); - m_settings.Save(si); -} - -void SDLHostInterface::QueueUpdateSettings() +void SDLHostInterface::RunLater(std::function callback) { SDL_Event ev = {}; ev.type = SDL_USEREVENT; - ev.user.code = m_update_settings_event_id; + ev.user.code = m_run_later_event_id; + ev.user.data1 = new std::function(std::move(callback)); SDL_PushEvent(&ev); } +void SDLHostInterface::SaveAndUpdateSettings() +{ + SDLSettingsInterface si(GetSettingsFileName().c_str()); + m_settings.Save(si); + m_settings.Load(si); +} + void SDLHostInterface::UpdateFullscreen() { SDL_SetWindowFullscreen(m_window, m_settings.display_fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); @@ -309,12 +311,12 @@ void SDLHostInterface::HandleSDLEvent(const SDL_Event* event) case SDL_USEREVENT: { - if (static_cast(event->user.code) == m_update_settings_event_id) + if (static_cast(event->user.code) == m_run_later_event_id) { - UpdateSettings([this]() { - SDLSettingsInterface si(GetSettingsFileName().c_str()); - m_settings.Load(si); - }); + std::function* callback = static_cast*>(event->user.data1); + Assert(callback); + (*callback)(); + delete callback; } } break; @@ -784,10 +786,7 @@ void SDLHostInterface::DrawQuickSettingsMenu() settings_changed |= ImGui::MenuItem("Display Linear Filtering", nullptr, &m_settings.display_linear_filtering); if (settings_changed) - { - SaveSettings(); - QueueUpdateSettings(); - } + RunLater(std::bind(&SDLHostInterface::SaveAndUpdateSettings, this)); } void SDLHostInterface::DrawDebugMenu() @@ -851,7 +850,7 @@ void SDLHostInterface::DrawPoweredOffWindow() ImGui::SetCursorPosX(button_left); if (ImGui::Button("Resume", button_size)) { - ResumeSystemFromMostRecentState(); + RunLater([this]() { ResumeSystemFromMostRecentState(); }); ClearImGuiFocus(); } ImGui::NewLine(); @@ -859,7 +858,7 @@ void SDLHostInterface::DrawPoweredOffWindow() ImGui::SetCursorPosX(button_left); if (ImGui::Button("Start Disc", button_size)) { - DoStartDisc(); + RunLater([this]() { DoStartDisc(); }); ClearImGuiFocus(); } ImGui::NewLine(); @@ -867,7 +866,7 @@ void SDLHostInterface::DrawPoweredOffWindow() ImGui::SetCursorPosX(button_left); if (ImGui::Button("Start BIOS", button_size)) { - BootSystemFromFile(nullptr); + RunLater([this]() { BootSystemFromFile(nullptr); }); ClearImGuiFocus(); } ImGui::NewLine(); @@ -883,7 +882,7 @@ void SDLHostInterface::DrawPoweredOffWindow() std::snprintf(buf, sizeof(buf), "State %u", i); if (ImGui::MenuItem(buf)) { - LoadState(true, i); + RunLater([this, i]() { LoadState(true, i); }); ClearImGuiFocus(); } } @@ -1152,10 +1151,7 @@ void SDLHostInterface::DrawSettingsWindow() ImGui::End(); if (settings_changed) - { - SaveSettings(); - QueueUpdateSettings(); - } + RunLater(std::bind(&SDLHostInterface::SaveAndUpdateSettings, this)); } void SDLHostInterface::DrawAboutWindow() diff --git a/src/duckstation-sdl/sdl_host_interface.h b/src/duckstation-sdl/sdl_host_interface.h index 02242e2b2..815893983 100644 --- a/src/duckstation-sdl/sdl_host_interface.h +++ b/src/duckstation-sdl/sdl_host_interface.h @@ -83,8 +83,10 @@ private: void DestroyDisplay(); void CreateImGuiContext(); - void SaveSettings(); - void QueueUpdateSettings(); + /// Executes a callback later, after the UI has finished rendering. Needed to boot while rendering ImGui. + void RunLater(std::function callback); + + void SaveAndUpdateSettings(); void UpdateFullscreen(); @@ -115,7 +117,7 @@ private: KeyboardControllerActionMap m_keyboard_button_mapping; - u32 m_update_settings_event_id = 0; + u32 m_run_later_event_id = 0; bool m_quit_request = false; bool m_frame_step_request = false;