diff --git a/src/video/x11/SDL_x11keyboard.c b/src/video/x11/SDL_x11keyboard.c index fecde82a62..d1d8b5bf29 100644 --- a/src/video/x11/SDL_x11keyboard.c +++ b/src/video/x11/SDL_x11keyboard.c @@ -766,6 +766,18 @@ void X11_CreateInputContext(SDL_WindowData *data) #endif // X_HAVE_UTF8_STRING } + +void X11_DestroyInputContext(SDL_WindowData *data) +{ +#ifdef X_HAVE_UTF8_STRING + X11_XDestroyIC(data->ic); + SDL_free(data->preedit_text); + SDL_free(data->preedit_feedback); + data->preedit_text = NULL; + data->preedit_feedback = NULL; +#endif +} + static void X11_ResetXIM(SDL_VideoDevice *_this, SDL_Window *window) { #ifdef X_HAVE_UTF8_STRING diff --git a/src/video/x11/SDL_x11keyboard.h b/src/video/x11/SDL_x11keyboard.h index bc053f5fbb..a61c419fc7 100644 --- a/src/video/x11/SDL_x11keyboard.h +++ b/src/video/x11/SDL_x11keyboard.h @@ -27,6 +27,7 @@ extern bool X11_InitKeyboard(SDL_VideoDevice *_this); extern void X11_UpdateKeymap(SDL_VideoDevice *_this, bool send_event); extern void X11_QuitKeyboard(SDL_VideoDevice *_this); extern void X11_CreateInputContext(SDL_WindowData *data); +extern void X11_DestroyInputContext(SDL_WindowData *data); extern void X11_ClearComposition(SDL_WindowData *data); extern bool X11_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props); extern bool X11_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window); diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c index d4929a5fa6..eaa0cd9e10 100644 --- a/src/video/x11/SDL_x11window.c +++ b/src/video/x11/SDL_x11window.c @@ -398,8 +398,7 @@ static bool SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, Window w } else { SDL_WindowData ** new_windowlist = (SDL_WindowData **)SDL_realloc(windowlist, (numwindows + 1) * sizeof(*windowlist)); if (!new_windowlist) { - SDL_free(data); - return false; + goto error_cleanup; } windowlist = new_windowlist; windowlist[numwindows] = data; @@ -458,9 +457,42 @@ static bool SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, Window w SDL_SetNumberProperty(props, SDL_PROP_WINDOW_X11_SCREEN_NUMBER, screen); SDL_SetNumberProperty(props, SDL_PROP_WINDOW_X11_WINDOW_NUMBER, data->xwindow); + +#if defined(SDL_VIDEO_OPENGL_ES) || defined(SDL_VIDEO_OPENGL_ES2) || defined(SDL_VIDEO_OPENGL_EGL) + if ((window->flags & SDL_WINDOW_OPENGL) && + ((_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) || + SDL_GetHintBoolean(SDL_HINT_VIDEO_FORCE_EGL, false)) +#ifdef SDL_VIDEO_OPENGL_GLX + && (!_this->gl_data || X11_GL_UseEGL(_this)) +#endif + ) { +#ifdef SDL_VIDEO_OPENGL_EGL + if (!_this->egl_data) { + goto error_cleanup; + } + + // Create the GLES window surface + data->egl_surface = SDL_EGL_CreateSurface(_this, window, (NativeWindowType)w); + + if (data->egl_surface == EGL_NO_SURFACE) { + SDL_SetError("Could not create GLES window surface"); + goto error_cleanup; + } +#else + SDL_SetError("Could not create GLES window surface (EGL support not configured)"); + goto error_cleanup; +#endif // SDL_VIDEO_OPENGL_EGL + } +#endif + // All done! window->internal = data; return true; + +error_cleanup: + X11_DestroyInputContext(data); + SDL_free(data); + return false; } static void SetupWindowInput(SDL_VideoDevice *_this, SDL_Window *window) @@ -858,31 +890,6 @@ bool X11_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Properties } #endif /* SDL_VIDEO_DRIVER_X11_XSYNC */ -#if defined(SDL_VIDEO_OPENGL_ES) || defined(SDL_VIDEO_OPENGL_ES2) || defined(SDL_VIDEO_OPENGL_EGL) - if ((window->flags & SDL_WINDOW_OPENGL) && - ((_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) || - SDL_GetHintBoolean(SDL_HINT_VIDEO_FORCE_EGL, false)) -#ifdef SDL_VIDEO_OPENGL_GLX - && (!_this->gl_data || X11_GL_UseEGL(_this)) -#endif - ) { -#ifdef SDL_VIDEO_OPENGL_EGL - if (!_this->egl_data) { - return false; - } - - // Create the GLES window surface - windowdata->egl_surface = SDL_EGL_CreateSurface(_this, window, (NativeWindowType)w); - - if (windowdata->egl_surface == EGL_NO_SURFACE) { - return SDL_SetError("Could not create GLES window surface"); - } -#else - return SDL_SetError("Could not create GLES window surface (EGL support not configured)"); -#endif // SDL_VIDEO_OPENGL_EGL - } -#endif - #ifdef SDL_VIDEO_DRIVER_X11_XSHAPE // Tooltips do not receive input if (window->flags & SDL_WINDOW_TOOLTIP) { @@ -2180,13 +2187,8 @@ void X11_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window) } } } -#ifdef X_HAVE_UTF8_STRING - if (data->ic) { - X11_XDestroyIC(data->ic); - SDL_free(data->preedit_text); - SDL_free(data->preedit_feedback); - } -#endif + + X11_DestroyInputContext(data); #ifdef SDL_VIDEO_DRIVER_X11_XSYNC X11_TermResizeSync(window);