From 32d9c93af3e5ff999444eb8e52699110b0fe9afd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Fri, 28 Jun 2024 17:17:20 +0200 Subject: [PATCH] Improve handling of rendering startup errors --- platform/android/display_server_android.cpp | 10 +++++++++- platform/ios/display_server_ios.mm | 9 ++++++++- platform/linuxbsd/wayland/display_server_wayland.cpp | 9 ++++++++- platform/linuxbsd/x11/display_server_x11.cpp | 10 ++++++++-- platform/windows/display_server_windows.cpp | 9 ++++++++- servers/rendering/rendering_device.cpp | 2 +- 6 files changed, 42 insertions(+), 7 deletions(-) diff --git a/platform/android/display_server_android.cpp b/platform/android/display_server_android.cpp index 288c37be29f0..06b304dcde35 100644 --- a/platform/android/display_server_android.cpp +++ b/platform/android/display_server_android.cpp @@ -607,6 +607,7 @@ DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, Dis ERR_PRINT(vformat("Failed to initialize %s context", rendering_driver)); memdelete(rendering_context); rendering_context = nullptr; + r_error = ERR_UNAVAILABLE; return; } @@ -627,6 +628,7 @@ DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, Dis ERR_PRINT(vformat("Failed to create %s window.", rendering_driver)); memdelete(rendering_context); rendering_context = nullptr; + r_error = ERR_UNAVAILABLE; return; } @@ -635,7 +637,13 @@ DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, Dis rendering_context->window_set_vsync_mode(MAIN_WINDOW_ID, p_vsync_mode); rendering_device = memnew(RenderingDevice); - rendering_device->initialize(rendering_context, MAIN_WINDOW_ID); + if (rendering_device->initialize(rendering_context, MAIN_WINDOW_ID) != OK) { + rendering_device = nullptr; + memdelete(rendering_context); + rendering_context = nullptr; + r_error = ERR_UNAVAILABLE; + return; + } rendering_device->screen_create(MAIN_WINDOW_ID); RendererCompositorRD::make_current(); diff --git a/platform/ios/display_server_ios.mm b/platform/ios/display_server_ios.mm index a454dd5ba003..802fbefc0dbb 100644 --- a/platform/ios/display_server_ios.mm +++ b/platform/ios/display_server_ios.mm @@ -91,6 +91,7 @@ ERR_PRINT(vformat("Failed to initialize %s context", rendering_driver)); memdelete(rendering_context); rendering_context = nullptr; + r_error = ERR_UNAVAILABLE; return; } @@ -107,7 +108,13 @@ rendering_context->window_set_vsync_mode(MAIN_WINDOW_ID, p_vsync_mode); rendering_device = memnew(RenderingDevice); - rendering_device->initialize(rendering_context, MAIN_WINDOW_ID); + if (rendering_device->initialize(rendering_context, MAIN_WINDOW_ID) != OK) { + rendering_device = nullptr; + memdelete(rendering_context); + rendering_context = nullptr; + r_error = ERR_UNAVAILABLE; + return; + } rendering_device->screen_create(MAIN_WINDOW_ID); RendererCompositorRD::make_current(); diff --git a/platform/linuxbsd/wayland/display_server_wayland.cpp b/platform/linuxbsd/wayland/display_server_wayland.cpp index c05ad93f4206..adc9beed66ea 100644 --- a/platform/linuxbsd/wayland/display_server_wayland.cpp +++ b/platform/linuxbsd/wayland/display_server_wayland.cpp @@ -1469,7 +1469,14 @@ DisplayServerWayland::DisplayServerWayland(const String &p_rendering_driver, Win #ifdef RD_ENABLED if (rendering_context) { rendering_device = memnew(RenderingDevice); - rendering_device->initialize(rendering_context, MAIN_WINDOW_ID); + if (rendering_device->initialize(rendering_context, MAIN_WINDOW_ID) != OK) { + memdelete(rendering_device); + rendering_device = nullptr; + memdelete(rendering_context); + rendering_context = nullptr; + r_error = ERR_UNAVAILABLE; + return; + } rendering_device->screen_create(MAIN_WINDOW_ID); RendererCompositorRD::make_current(); diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp index ea84130828d5..49f202883d9e 100644 --- a/platform/linuxbsd/x11/display_server_x11.cpp +++ b/platform/linuxbsd/x11/display_server_x11.cpp @@ -6261,8 +6261,14 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode #if defined(RD_ENABLED) if (rendering_context) { - rendering_device = memnew(RenderingDevice); - rendering_device->initialize(rendering_context, MAIN_WINDOW_ID); + if (rendering_device->initialize(rendering_context, MAIN_WINDOW_ID) != OK) { + memdelete(rendering_device); + rendering_device = nullptr; + memdelete(rendering_context); + rendering_context = nullptr; + r_error = ERR_UNAVAILABLE; + return; + } rendering_device->screen_create(MAIN_WINDOW_ID); RendererCompositorRD::make_current(); diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index 838beddac285..8d26a705a995 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -5873,7 +5873,14 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win #if defined(RD_ENABLED) if (rendering_context) { rendering_device = memnew(RenderingDevice); - rendering_device->initialize(rendering_context, MAIN_WINDOW_ID); + if (rendering_device->initialize(rendering_context, MAIN_WINDOW_ID) != OK) { + memdelete(rendering_device); + rendering_device = nullptr; + memdelete(rendering_context); + rendering_context = nullptr; + r_error = ERR_UNAVAILABLE; + return; + } rendering_device->screen_create(MAIN_WINDOW_ID); RendererCompositorRD::make_current(); diff --git a/servers/rendering/rendering_device.cpp b/servers/rendering/rendering_device.cpp index 38f1fe57bd4e..59f7b3d9e160 100644 --- a/servers/rendering/rendering_device.cpp +++ b/servers/rendering/rendering_device.cpp @@ -5507,7 +5507,7 @@ Error RenderingDevice::initialize(RenderingContextDriver *p_context, DisplayServ for (uint32_t i = 0; i < frames.size(); i++) { // Staging was never used, create a block. err = _insert_staging_block(); - ERR_CONTINUE(err != OK); + ERR_FAIL_COND_V(err, FAILED); } draw_list = nullptr;