From d5a5dd52e82c171a3eba449cfdee9eb3be1323d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Fri, 5 Jan 2024 18:27:10 +0100 Subject: [PATCH] Avoid several null-dereferences of ApiContextRD --- platform/android/display_server_android.cpp | 9 ++++++--- platform/ios/display_server_ios.mm | 6 ++++-- platform/linuxbsd/x11/display_server_x11.cpp | 3 ++- platform/windows/display_server_windows.cpp | 3 ++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/platform/android/display_server_android.cpp b/platform/android/display_server_android.cpp index 340823baacd6..4a9915379ae3 100644 --- a/platform/android/display_server_android.cpp +++ b/platform/android/display_server_android.cpp @@ -538,9 +538,10 @@ void DisplayServerAndroid::reset_window() { #endif if (context_rd->window_create(MAIN_WINDOW_ID, last_vsync_mode, display_size.width, display_size.height, &wpd) != OK) { + ERR_PRINT(vformat("Failed to reset %s window.", context_rd->get_api_name())); memdelete(context_rd); context_rd = nullptr; - ERR_FAIL_MSG(vformat("Failed to reset %s window.", context_rd->get_api_name())); + return; } } #endif @@ -575,9 +576,10 @@ DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, Dis if (context_rd) { if (context_rd->initialize() != OK) { + ERR_PRINT(vformat("Failed to initialize %s context", context_rd->get_api_name())); memdelete(context_rd); context_rd = nullptr; - ERR_FAIL_MSG(vformat("Failed to initialize %s context", context_rd->get_api_name())); + return; } Size2i display_size = OS_Android::get_singleton()->get_display_size(); @@ -596,9 +598,10 @@ DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, Dis #endif if (context_rd->window_create(MAIN_WINDOW_ID, p_vsync_mode, display_size.width, display_size.height, &wpd) != OK) { + ERR_PRINT(vformat("Failed to create %s window.", context_rd->get_api_name())); memdelete(context_rd); context_rd = nullptr; - ERR_FAIL_MSG(vformat("Failed to create %s window.", context_rd->get_api_name())); + return; } rendering_device = memnew(RenderingDevice); diff --git a/platform/ios/display_server_ios.mm b/platform/ios/display_server_ios.mm index c31f503605b3..16299d0450ea 100644 --- a/platform/ios/display_server_ios.mm +++ b/platform/ios/display_server_ios.mm @@ -87,17 +87,19 @@ if (context_rd) { if (context_rd->initialize() != OK) { + ERR_PRINT(vformat("Failed to initialize %s context", context_rd->get_api_name())); memdelete(context_rd); context_rd = nullptr; - ERR_FAIL_MSG(vformat("Failed to initialize %s context", context_rd->get_api_name())); + return; } Size2i size = Size2i(layer.bounds.size.width, layer.bounds.size.height) * screen_get_max_scale(); if (context_rd->window_create(MAIN_WINDOW_ID, p_vsync_mode, size.width, size.height, &wpd) != OK) { + ERR_PRINT(vformat("Failed to create %s window.", context_rd->get_api_name())); memdelete(context_rd); context_rd = nullptr; r_error = ERR_UNAVAILABLE; - ERR_FAIL_MSG(vformat("Failed to create %s window.", context_rd->get_api_name())); + return; } rendering_device = memnew(RenderingDevice); diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp index 1434342bbc76..3893b05ab879 100644 --- a/platform/linuxbsd/x11/display_server_x11.cpp +++ b/platform/linuxbsd/x11/display_server_x11.cpp @@ -6028,10 +6028,11 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode if (context_rd) { if (context_rd->initialize() != OK) { + ERR_PRINT(vformat("Could not initialize %s", context_rd->get_api_name())); memdelete(context_rd); context_rd = nullptr; r_error = ERR_CANT_CREATE; - ERR_FAIL_MSG(vformat("Could not initialize %s", context_rd->get_api_name())); + return; } driver_found = true; } diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index 2bec804c7c76..11010709ddba 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -4344,10 +4344,11 @@ DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode, } #endif if (context_rd->window_create(id, p_vsync_mode, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top, &wpd) != OK) { + ERR_PRINT(vformat("Failed to create %s Window.", context_rd->get_api_name())); memdelete(context_rd); context_rd = nullptr; windows.erase(id); - ERR_FAIL_V_MSG(INVALID_WINDOW_ID, vformat("Failed to create %s Window.", context_rd->get_api_name())); + return INVALID_WINDOW_ID; } wd.context_created = true; }