From 6b8e0388206475c9fae364474c84624fa5a49599 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Tue, 3 Mar 2015 11:20:16 +0100 Subject: [PATCH] fixed using SDL_DisplayFormat() even if video is not initialized yet --- src/libgame/sdl.c | 32 +++++++++++++++++++++++++------- src/libgame/system.c | 2 ++ src/libgame/system.h | 2 ++ 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 22e96da8..8b8720c3 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -198,6 +198,9 @@ boolean SDLSetNativeSurface(SDL_Surface **surface) new_surface = SDL_ConvertSurface(*surface, backbuffer->surface->format, 0); + if (new_surface == NULL) + Error(ERR_EXIT, "SDL_ConvertSurface() failed: %s", SDL_GetError()); + SDL_FreeSurface(*surface); *surface = new_surface; @@ -207,14 +210,20 @@ boolean SDLSetNativeSurface(SDL_Surface **surface) SDL_Surface *SDLGetNativeSurface(SDL_Surface *surface) { + SDL_Surface *new_surface; + if (surface == NULL) return NULL; - if (backbuffer == NULL || - backbuffer->surface == NULL) - return SDL_ConvertSurface(surface, surface->format, 0); + if (backbuffer && backbuffer->surface) + new_surface = SDL_ConvertSurface(surface, backbuffer->surface->format, 0); + else + new_surface = SDL_ConvertSurface(surface, surface->format, 0); + + if (new_surface == NULL) + Error(ERR_EXIT, "SDL_ConvertSurface() failed: %s", SDL_GetError()); - return SDL_ConvertSurface(surface, backbuffer->surface->format, 0); + return new_surface; } #else @@ -223,7 +232,9 @@ boolean SDLSetNativeSurface(SDL_Surface **surface) { SDL_Surface *new_surface; - if (surface == NULL) + if (surface == NULL || + *surface == NULL || + !video.initialized) return FALSE; new_surface = SDL_DisplayFormat(*surface); @@ -240,10 +251,17 @@ boolean SDLSetNativeSurface(SDL_Surface **surface) SDL_Surface *SDLGetNativeSurface(SDL_Surface *surface) { - SDL_Surface *new_surface = SDL_DisplayFormat(surface); + SDL_Surface *new_surface; + + if (video.initialized) + new_surface = SDL_DisplayFormat(surface); + else + new_surface = SDL_ConvertSurface(surface, surface->format, SURFACE_FLAGS); if (new_surface == NULL) - Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError()); + Error(ERR_EXIT, "%s() failed: %s", + (video.initialized ? "SDL_DisplayFormat" : "SDL_ConvertSurface"), + SDL_GetError()); return new_surface; } diff --git a/src/libgame/system.c b/src/libgame/system.c index f45e87e8..c04c77e5 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -361,6 +361,8 @@ void InitVideoBuffer(int width, int height, int depth, boolean fullscreen) SDLInitVideoBuffer(&backbuffer, &window, fullscreen); + video.initialized = TRUE; + drawto = backbuffer; } diff --git a/src/libgame/system.h b/src/libgame/system.h index bb78fbe9..5050c726 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -729,6 +729,8 @@ struct VideoSystemInfo boolean window_scaling_available; int window_scaling_percent; char *window_scaling_quality; + + boolean initialized; }; struct AudioSystemInfo -- 2.34.1