Android: Handle some possible surface loss cases

This commit is contained in:
Connor McLaughlin 2021-06-07 18:13:05 +10:00
parent 141fac0481
commit 20afc1c4a1
3 changed files with 10 additions and 7 deletions

View file

@ -754,13 +754,13 @@ void AndroidHostInterface::SurfaceChanged(ANativeWindow* surface, int format, in
wi.surface_refresh_rate = GetRefreshRate(); wi.surface_refresh_rate = GetRefreshRate();
wi.surface_scale = GetSurfaceScale(width, height); wi.surface_scale = GetSurfaceScale(width, height);
m_display->ChangeRenderWindow(wi); const bool surface_valid = m_display->ChangeRenderWindow(wi) && surface;
if (surface) if (surface_valid)
OnHostDisplayResized(); OnHostDisplayResized();
if (surface && System::GetState() == System::State::Paused) if (surface_valid && System::GetState() == System::State::Paused)
PauseSystem(false); PauseSystem(false);
else if (!surface && System::IsRunning()) else if (!surface_valid && System::IsRunning())
PauseSystem(true); PauseSystem(true);
} }
} }

View file

@ -742,7 +742,8 @@ bool SwapChain::ResizeSwapChain(u32 new_width /* = 0 */, u32 new_height /* = 0 *
if (!CreateSwapChain() || !SetupSwapChainImages()) if (!CreateSwapChain() || !SetupSwapChainImages())
{ {
Panic("Failed to re-configure swap chain images, this is fatal (for now)"); DestroySwapChainImages();
DestroySwapChain();
return false; return false;
} }
@ -755,7 +756,8 @@ bool SwapChain::RecreateSwapChain()
if (!CreateSwapChain() || !SetupSwapChainImages()) if (!CreateSwapChain() || !SetupSwapChainImages())
{ {
Panic("Failed to re-configure swap chain images, this is fatal (for now)"); DestroySwapChainImages();
DestroySwapChain();
return false; return false;
} }

View file

@ -576,7 +576,7 @@ bool VulkanHostDisplay::DoneRenderContextCurrent()
bool VulkanHostDisplay::Render() bool VulkanHostDisplay::Render()
{ {
if (ShouldSkipDisplayingFrame()) if (ShouldSkipDisplayingFrame() || !m_swap_chain)
{ {
if (ImGui::GetCurrentContext()) if (ImGui::GetCurrentContext())
ImGui::Render(); ImGui::Render();
@ -602,6 +602,7 @@ bool VulkanHostDisplay::Render()
{ {
Log_ErrorPrint("Failed to recreate surface after loss"); Log_ErrorPrint("Failed to recreate surface after loss");
g_vulkan_context->ExecuteCommandBuffer(false); g_vulkan_context->ExecuteCommandBuffer(false);
m_swap_chain.reset();
return false; return false;
} }