From 919e526fd8d1cace9ef3573366ee1225a2e6c1bb Mon Sep 17 00:00:00 2001 From: MechaCat02 Date: Sun, 12 Jul 2026 15:44:11 +0200 Subject: [PATCH] [Fix] Screenshot: null-check presenter before use (fixes F12 crash) TakeScreenshot() called GetGraphicsSystemPresenter()->CaptureGuestOutput() and only tested the pointer for null AFTER dereferencing it, so taking a screenshot with no live presenter dereferenced null and crashed. Check for null first, and re-enable notifications on the capture-failure path too. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/xenia/app/emulator_window.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/xenia/app/emulator_window.cc b/src/xenia/app/emulator_window.cc index 48e84a7c5..8e3a31540 100644 --- a/src/xenia/app/emulator_window.cc +++ b/src/xenia/app/emulator_window.cc @@ -1134,10 +1134,20 @@ void EmulatorWindow::OnMouseUp(const ui::MouseEvent& e) { void EmulatorWindow::TakeScreenshot() { xe::ui::RawImage image; + // Null-check the presenter BEFORE dereferencing it. The original condition + // called CaptureGuestOutput() on the pointer and only tested it for null + // afterwards, so pressing the screenshot key before/without a live presenter + // dereferenced a null pointer and crashed. + auto* presenter = GetGraphicsSystemPresenter(); + if (presenter == nullptr) { + XELOGE("No graphics presenter available for screenshot"); + return; + } + imgui_drawer_->EnableNotifications(false); - if (!GetGraphicsSystemPresenter()->CaptureGuestOutput(image) || - GetGraphicsSystemPresenter() == nullptr) { + if (!presenter->CaptureGuestOutput(image)) { + imgui_drawer_->EnableNotifications(true); XELOGE("Failed to capture guest output for screenshot"); return; }