From 83f368cdbece81af6ccb02baf8c35489679db9db Mon Sep 17 00:00:00 2001 From: jgmdev Date: Tue, 31 May 2022 14:57:26 -0400 Subject: [PATCH] core: check for sdl initialization errors --- src/main.c | 9 ++++++++- src/renwindow.c | 11 ++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 0ce74862..2f44d7c9 100644 --- a/src/main.c +++ b/src/main.c @@ -91,7 +91,10 @@ int main(int argc, char **argv) { signal(SIGPIPE, SIG_IGN); #endif - SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS); + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) != 0) { + fprintf(stderr, "Error initializing sdl: %s", SDL_GetError()); + exit(1); + } SDL_EnableScreenSaver(); SDL_EventState(SDL_DROPFILE, SDL_ENABLE); atexit(SDL_Quit); @@ -122,6 +125,10 @@ int main(int argc, char **argv) { "", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, dm.w * 0.8, dm.h * 0.8, SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_HIDDEN); init_window_icon(); + if (!window) { + fprintf(stderr, "Error creating lite-xl window: %s", SDL_GetError()); + exit(1); + } ren_init(window); lua_State *L; diff --git a/src/renwindow.c b/src/renwindow.c index c2aa0096..3f83f294 100644 --- a/src/renwindow.c +++ b/src/renwindow.c @@ -35,6 +35,10 @@ void renwin_init_surface(UNUSED RenWindow *ren) { int w, h; SDL_GL_GetDrawableSize(ren->window, &w, &h); ren->surface = SDL_CreateRGBSurfaceWithFormat(0, w, h, 32, SDL_PIXELFORMAT_BGRA32); + if (!ren->surface) { + fprintf(stderr, "Error creating surface: %s", SDL_GetError()); + exit(1); + } setup_renderer(ren, w, h); #endif } @@ -68,7 +72,12 @@ SDL_Surface *renwin_get_surface(RenWindow *ren) { #ifdef LITE_USE_SDL_RENDERER return ren->surface; #else - return SDL_GetWindowSurface(ren->window); + SDL_Surface *surface = SDL_GetWindowSurface(ren->window); + if (!surface) { + fprintf(stderr, "Error getting window surface: %s", SDL_GetError()); + exit(1); + } + return surface; #endif }