diff --git a/src/xenia/app/emulator_window.cc b/src/xenia/app/emulator_window.cc index eda77b866..7af4dec9d 100644 --- a/src/xenia/app/emulator_window.cc +++ b/src/xenia/app/emulator_window.cc @@ -32,7 +32,9 @@ EmulatorWindow::EmulatorWindow(Emulator* emulator) loop_(ui::Loop::Create()), window_(ui::Window::Create(loop_.get(), kBaseTitle)) {} -EmulatorWindow::~EmulatorWindow() = default; +EmulatorWindow::~EmulatorWindow() { + loop_->PostSynchronous([this]() { window_.reset(); }); +} std::unique_ptr EmulatorWindow::Create(Emulator* emulator) { std::unique_ptr emulator_window(new EmulatorWindow(emulator)); diff --git a/src/xenia/app/xenia_main.cc b/src/xenia/app/xenia_main.cc index 15bd5829b..0092a224e 100644 --- a/src/xenia/app/xenia_main.cc +++ b/src/xenia/app/xenia_main.cc @@ -83,6 +83,8 @@ int xenia_main(std::vector& args) { result = emulator->LaunchPath(abs_path); if (XFAILED(result)) { XELOGE("Failed to launch target: %.8X", result); + emulator.reset(); + emulator_window.reset(); return 1; } diff --git a/src/xenia/gpu/gl4/command_processor.cc b/src/xenia/gpu/gl4/command_processor.cc index fc0709a8c..acab07181 100644 --- a/src/xenia/gpu/gl4/command_processor.cc +++ b/src/xenia/gpu/gl4/command_processor.cc @@ -104,12 +104,6 @@ void CommandProcessor::Shutdown() { write_ptr_index_event_->Set(); worker_thread_->Wait(0, 0, 0, nullptr); worker_thread_.reset(); - - all_pipelines_.clear(); - all_shaders_.clear(); - shader_cache_.clear(); - - context_.reset(); } void CommandProcessor::RequestFrameTrace(const std::wstring& root_path) { @@ -227,7 +221,6 @@ void CommandProcessor::WorkerThreadMain() { } ShutdownGL(); - context_->ClearCurrent(); } bool CommandProcessor::SetupGL() { @@ -466,6 +459,12 @@ void CommandProcessor::ShutdownGL() { texture_cache_.Shutdown(); draw_batcher_.Shutdown(); scratch_buffer_.Shutdown(); + + all_pipelines_.clear(); + all_shaders_.clear(); + shader_cache_.clear(); + + context_.reset(); } void CommandProcessor::InitializeRingBuffer(uint32_t ptr, uint32_t page_count) { diff --git a/src/xenia/ui/window_win.cc b/src/xenia/ui/window_win.cc index 2c64e8ff7..f44f8ad55 100644 --- a/src/xenia/ui/window_win.cc +++ b/src/xenia/ui/window_win.cc @@ -137,10 +137,7 @@ void Win32Window::EnableMMCSS() { FreeLibrary(hLibrary); } -void Win32Window::OnDestroy() { - super::OnDestroy(); - hwnd_ = nullptr; -} +void Win32Window::OnDestroy() { super::OnDestroy(); } void Win32Window::OnClose() { if (!closing_ && hwnd_) {