From 5d26c2177f5d1e9b8668debeabd69e0ca9d91691 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Mon, 4 Nov 2019 01:57:08 +1000 Subject: [PATCH] GPU/HW: Don't crash when switching to incompatible renderer --- src/core/gpu_hw_d3d11.cpp | 10 +++++----- src/core/gpu_hw_opengl.cpp | 12 ++++++------ src/core/system.cpp | 2 ++ src/duckstation/sdl_host_interface.cpp | 2 +- src/duckstation/sdl_host_interface.h | 2 +- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/core/gpu_hw_d3d11.cpp b/src/core/gpu_hw_d3d11.cpp index f1b414ec8..403c6644e 100644 --- a/src/core/gpu_hw_d3d11.cpp +++ b/src/core/gpu_hw_d3d11.cpp @@ -20,17 +20,17 @@ GPU_HW_D3D11::~GPU_HW_D3D11() bool GPU_HW_D3D11::Initialize(HostDisplay* host_display, System* system, DMA* dma, InterruptController* interrupt_controller, Timers* timers) { - SetCapabilities(); - - if (!GPU_HW::Initialize(host_display, system, dma, interrupt_controller, timers)) - return false; - if (host_display->GetRenderAPI() != HostDisplay::RenderAPI::D3D11) { Log_ErrorPrintf("Host render API is incompatible"); return false; } + SetCapabilities(); + + if (!GPU_HW::Initialize(host_display, system, dma, interrupt_controller, timers)) + return false; + m_device = static_cast(host_display->GetHostRenderDevice()); m_context = static_cast(host_display->GetHostRenderContext()); if (!m_device || !m_context) diff --git a/src/core/gpu_hw_opengl.cpp b/src/core/gpu_hw_opengl.cpp index bba174135..c31288074 100644 --- a/src/core/gpu_hw_opengl.cpp +++ b/src/core/gpu_hw_opengl.cpp @@ -19,17 +19,17 @@ GPU_HW_OpenGL::~GPU_HW_OpenGL() bool GPU_HW_OpenGL::Initialize(HostDisplay* host_display, System* system, DMA* dma, InterruptController* interrupt_controller, Timers* timers) { - SetCapabilities(); - - if (!GPU_HW::Initialize(host_display, system, dma, interrupt_controller, timers)) - return false; - - if (m_host_display->GetRenderAPI() != HostDisplay::RenderAPI::OpenGL) + if (host_display->GetRenderAPI() != HostDisplay::RenderAPI::OpenGL) { Log_ErrorPrintf("Host render API type is incompatible"); return false; } + SetCapabilities(); + + if (!GPU_HW::Initialize(host_display, system, dma, interrupt_controller, timers)) + return false; + CreateFramebuffer(); CreateVertexBuffer(); CreateUniformBuffer(); diff --git a/src/core/system.cpp b/src/core/system.cpp index 2e8e3eee3..5a26cc82d 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -113,9 +113,11 @@ bool System::CreateGPU() m_gpu = GPU::CreateHardwareOpenGLRenderer(); break; +#ifdef WIN32 case Settings::GPURenderer::HardwareD3D11: m_gpu = GPU::CreateHardwareD3D11Renderer(); break; +#endif case Settings::GPURenderer::Software: default: diff --git a/src/duckstation/sdl_host_interface.cpp b/src/duckstation/sdl_host_interface.cpp index 39457955b..dcd968ee9 100644 --- a/src/duckstation/sdl_host_interface.cpp +++ b/src/duckstation/sdl_host_interface.cpp @@ -71,7 +71,7 @@ bool SDLHostInterface::CreateSDLWindow() bool SDLHostInterface::CreateDisplay() { -#ifdef Y_PLATFORM_WINDOWS +#ifdef WIN32 m_display = UseOpenGLRenderer() ? OpenGLHostDisplay::Create(m_window) : D3D11HostDisplay::Create(m_window); #else m_display = OpenGLHostDisplay::Create(m_window); diff --git a/src/duckstation/sdl_host_interface.h b/src/duckstation/sdl_host_interface.h index acab84d16..80d70e624 100644 --- a/src/duckstation/sdl_host_interface.h +++ b/src/duckstation/sdl_host_interface.h @@ -50,7 +50,7 @@ private: bool HasSystem() const { return static_cast(m_system); } -#ifdef Y_PLATFORM_WINDOWS +#ifdef WIN32 bool UseOpenGLRenderer() const { return m_settings.gpu_renderer == Settings::GPURenderer::HardwareOpenGL; } #else bool UseOpenGLRenderer() const { return true; }