From 08845dc3f000cd4de4ce1d6faabda398a5aed8b9 Mon Sep 17 00:00:00 2001 From: clayjohn Date: Tue, 7 Mar 2023 09:24:05 -0800 Subject: Propogate errors when creating an OpenGL context fails in X11 (cherry picked from commit e7ea3ef53189d4bc94c784e4805a5311701ba9aa) --- platform/linuxbsd/x11/display_server_x11.cpp | 4 +++- platform/linuxbsd/x11/gl_manager_x11.cpp | 23 +++++++++++++++++++---- platform/linuxbsd/x11/gl_manager_x11.h | 2 +- 3 files changed, 23 insertions(+), 6 deletions(-) (limited to 'platform') diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp index 7a59a1a398..aa31ec83b2 100644 --- a/platform/linuxbsd/x11/display_server_x11.cpp +++ b/platform/linuxbsd/x11/display_server_x11.cpp @@ -4873,7 +4873,9 @@ DisplayServerX11::WindowID DisplayServerX11::_create_window(WindowMode p_mode, V #ifdef GLES3_ENABLED if (gl_manager) { - visualInfo = gl_manager->get_vi(x11_display); + Error err; + visualInfo = gl_manager->get_vi(x11_display, err); + ERR_FAIL_COND_V_MSG(err != OK, INVALID_WINDOW_ID, "Can't acquire visual info from display."); vi_selected = true; } #endif diff --git a/platform/linuxbsd/x11/gl_manager_x11.cpp b/platform/linuxbsd/x11/gl_manager_x11.cpp index 03ba95f475..ee767dfa80 100644 --- a/platform/linuxbsd/x11/gl_manager_x11.cpp +++ b/platform/linuxbsd/x11/gl_manager_x11.cpp @@ -83,8 +83,13 @@ int GLManager_X11::_find_or_create_display(Display *p_x11_display) { d.context = memnew(GLManager_X11_Private); d.context->glx_context = nullptr; - //Error err = _create_context(d); - _create_context(d); + Error err = _create_context(d); + + if (err != OK) { + _displays.remove_at(new_display_id); + return -1; + } + return new_display_id; } @@ -191,8 +196,14 @@ Error GLManager_X11::_create_context(GLDisplay &gl_display) { return OK; } -XVisualInfo GLManager_X11::get_vi(Display *p_display) { - return _displays[_find_or_create_display(p_display)].x_vi; +XVisualInfo GLManager_X11::get_vi(Display *p_display, Error &r_error) { + int display_id = _find_or_create_display(p_display); + if (display_id < 0) { + r_error = FAILED; + return XVisualInfo(); + } + r_error = OK; + return _displays[display_id].x_vi; } Error GLManager_X11::window_create(DisplayServer::WindowID p_window_id, ::Window p_window, Display *p_display, int p_width, int p_height) { @@ -211,6 +222,10 @@ Error GLManager_X11::window_create(DisplayServer::WindowID p_window_id, ::Window win.x11_window = p_window; win.gldisplay_id = _find_or_create_display(p_display); + if (win.gldisplay_id == -1) { + return FAILED; + } + // the display could be invalid .. check NYI GLDisplay &gl_display = _displays[win.gldisplay_id]; ::Display *x11_display = gl_display.x11_display; diff --git a/platform/linuxbsd/x11/gl_manager_x11.h b/platform/linuxbsd/x11/gl_manager_x11.h index 0eb8ab64f4..0203dff679 100644 --- a/platform/linuxbsd/x11/gl_manager_x11.h +++ b/platform/linuxbsd/x11/gl_manager_x11.h @@ -114,7 +114,7 @@ private: Error _create_context(GLDisplay &gl_display); public: - XVisualInfo get_vi(Display *p_display); + XVisualInfo get_vi(Display *p_display, Error &r_error); Error window_create(DisplayServer::WindowID p_window_id, ::Window p_window, Display *p_display, int p_width, int p_height); void window_destroy(DisplayServer::WindowID p_window_id); void window_resize(DisplayServer::WindowID p_window_id, int p_width, int p_height); -- cgit v1.2.3