From 5fd79254bd2c023477cee9a24029218510ed082d Mon Sep 17 00:00:00 2001 From: Stenzek Date: Tue, 26 Nov 2024 12:58:12 +1000 Subject: [PATCH] GPU: Fix crash when toggling software renderer --- src/core/gpu.h | 4 ++-- src/core/gpu_hw.cpp | 8 ++------ src/core/gpu_sw.cpp | 8 ++------ src/core/system.cpp | 10 +++++----- 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/core/gpu.h b/src/core/gpu.h index 55c3b8d4c..3469a513a 100644 --- a/src/core/gpu.h +++ b/src/core/gpu.h @@ -186,8 +186,8 @@ public: float ComputeDisplayAspectRatio() const; float ComputeAspectRatioCorrection() const; - static std::unique_ptr CreateHardwareRenderer(Error* error); - static std::unique_ptr CreateSoftwareRenderer(Error* error); + static std::unique_ptr CreateHardwareRenderer(); + static std::unique_ptr CreateSoftwareRenderer(); // Converts window coordinates into horizontal ticks and scanlines. Returns false if out of range. Used for lightguns. void ConvertScreenCoordinatesToDisplayCoordinates(float window_x, float window_y, float* display_x, diff --git a/src/core/gpu_hw.cpp b/src/core/gpu_hw.cpp index 81f606e84..5d940c9cf 100644 --- a/src/core/gpu_hw.cpp +++ b/src/core/gpu_hw.cpp @@ -4265,11 +4265,7 @@ void GPU_HW::DrawRendererStats() } } -std::unique_ptr GPU::CreateHardwareRenderer(Error* error) +std::unique_ptr GPU::CreateHardwareRenderer() { - std::unique_ptr gpu(std::make_unique()); - if (!gpu->Initialize(error)) - gpu.reset(); - - return gpu; + return std::make_unique(); } diff --git a/src/core/gpu_sw.cpp b/src/core/gpu_sw.cpp index a29d99860..c8b12fa87 100644 --- a/src/core/gpu_sw.cpp +++ b/src/core/gpu_sw.cpp @@ -824,11 +824,7 @@ void GPU_SW::UpdateCLUT(GPUTexturePaletteReg reg, bool clut_is_8bit) m_backend.PushCommand(cmd); } -std::unique_ptr GPU::CreateSoftwareRenderer(Error* error) +std::unique_ptr GPU::CreateSoftwareRenderer() { - std::unique_ptr gpu(std::make_unique()); - if (!gpu->Initialize(error)) - gpu.reset(); - - return gpu; + return std::make_unique(); } diff --git a/src/core/system.cpp b/src/core/system.cpp index ccc70d709..cfc60ba89 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -2432,11 +2432,11 @@ bool System::CreateGPU(GPURenderer renderer, bool is_switching, bool fullscreen, } if (renderer == GPURenderer::Software) - g_gpu = GPU::CreateSoftwareRenderer(error); + g_gpu = GPU::CreateSoftwareRenderer(); else - g_gpu = GPU::CreateHardwareRenderer(error); + g_gpu = GPU::CreateHardwareRenderer(); - if (!g_gpu) + if (!g_gpu->Initialize(error)) { ERROR_LOG("Failed to initialize {} renderer, falling back to software renderer", Settings::GetRendererName(renderer)); @@ -2445,8 +2445,8 @@ bool System::CreateGPU(GPURenderer renderer, bool is_switching, bool fullscreen, Settings::GetRendererName(renderer)), Host::OSD_CRITICAL_ERROR_DURATION); g_gpu.reset(); - g_gpu = GPU::CreateSoftwareRenderer(error); - if (!g_gpu) + g_gpu = GPU::CreateSoftwareRenderer(); + if (!g_gpu->Initialize(error)) { ERROR_LOG("Failed to create fallback software renderer."); if (!s_state.keep_gpu_device_on_shutdown)