From 805dac303926b42102da761e5e5ef7f9c7fb262e Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Thu, 22 Apr 2021 10:59:40 +0200 Subject: [PATCH] Resize renderer after [re]init Fixes crash on Android when app is brought back to the foreground Issue #228 --- core/emulator.h | 1 + core/nullDC.cpp | 11 ++++++++--- core/rend/gl4/gles.cpp | 8 ++------ core/rend/gles/gles.cpp | 3 ++- core/rend/gles/gltex.cpp | 3 ++- core/rend/mainui.cpp | 2 ++ 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/core/emulator.h b/core/emulator.h index 0c1fb614d..abc28bd92 100644 --- a/core/emulator.h +++ b/core/emulator.h @@ -46,6 +46,7 @@ bool dc_is_load_done(); void dc_cancel_load(); void dc_get_load_status(); bool dc_is_running(); +void dc_resize_renderer(); enum class Event { Start, diff --git a/core/nullDC.cpp b/core/nullDC.cpp index 7b429c717..bb89e030c 100644 --- a/core/nullDC.cpp +++ b/core/nullDC.cpp @@ -735,10 +735,8 @@ void SaveSettings() #endif } -void dc_resume() +void dc_resize_renderer() { - SetMemoryHandlers(); - settings.aica.NoBatch = config::ForceWindowsCE || config::DSPEnabled; int hres; int vres = config::RenderResolution; if (config::Widescreen && !config::Rotate90) @@ -759,6 +757,13 @@ void dc_resume() } if (renderer != nullptr) renderer->Resize(hres, vres); +} + +void dc_resume() +{ + SetMemoryHandlers(); + settings.aica.NoBatch = config::ForceWindowsCE || config::DSPEnabled; + dc_resize_renderer(); EventManager::event(Event::Resume); if (!emu_thread.thread.joinable()) diff --git a/core/rend/gl4/gles.cpp b/core/rend/gl4/gles.cpp index dcf411154..1823195d7 100644 --- a/core/rend/gl4/gles.cpp +++ b/core/rend/gl4/gles.cpp @@ -712,15 +712,11 @@ static bool RenderFrame(int width, int height) //setup render target first if (is_rtt) - { output_fbo = BindRTT(false); - if (output_fbo == 0) - return false; - } else - { output_fbo = init_output_framebuffer(rendering_width, rendering_height); - } + if (output_fbo == 0) + return false; glcache.Disable(GL_SCISSOR_TEST); diff --git a/core/rend/gles/gles.cpp b/core/rend/gles/gles.cpp index 10a07e9a9..94eabcaa9 100644 --- a/core/rend/gles/gles.cpp +++ b/core/rend/gles/gles.cpp @@ -1099,7 +1099,8 @@ bool RenderFrame(int width, int height) } else { - init_output_framebuffer(width, height); + if (init_output_framebuffer(width, height) == 0) + return false; } bool wide_screen_on = !is_rtt && config::Widescreen && !matrices.IsClipped() && !config::Rotate90; diff --git a/core/rend/gles/gltex.cpp b/core/rend/gles/gltex.cpp index d9a20980c..1a04890f9 100644 --- a/core/rend/gles/gltex.cpp +++ b/core/rend/gles/gltex.cpp @@ -523,7 +523,8 @@ GLuint init_output_framebuffer(int width, int height) // Check that our FBO creation was successful GLuint uStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER); - verify(uStatus == GL_FRAMEBUFFER_COMPLETE); + if (uStatus != GL_FRAMEBUFFER_COMPLETE) + return 0; glcache.Disable(GL_SCISSOR_TEST); glcache.ClearColor(0.f, 0.f, 0.f, 0.f); diff --git a/core/rend/mainui.cpp b/core/rend/mainui.cpp index 7906c7361..b890dcbf8 100644 --- a/core/rend/mainui.cpp +++ b/core/rend/mainui.cpp @@ -24,6 +24,7 @@ #include "oslib/oslib.h" #include "wsi/context.h" #include "cfg/option.h" +#include "emulator.h" bool mainui_enabled; u32 MainFrameCount; @@ -59,6 +60,7 @@ bool mainui_rend_frame() void mainui_init() { rend_init_renderer(); + dc_resize_renderer(); } void mainui_term()