Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid several null-dereferences of ApiContextRD #86843

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions platform/android/display_server_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions platform/ios/display_server_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion platform/linuxbsd/x11/display_server_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion platform/windows/display_server_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading