fixed using SDL_DisplayFormat() even if video is not initialized yet
authorHolger Schemel <info@artsoft.org>
Tue, 3 Mar 2015 10:20:16 +0000 (11:20 +0100)
committerHolger Schemel <info@artsoft.org>
Tue, 3 Mar 2015 10:20:16 +0000 (11:20 +0100)
src/libgame/sdl.c
src/libgame/system.c
src/libgame/system.h

index 22e96da8ba0aa00a6d1c7b72f4bbc27b9615b4d6..8b8720c320fcfe182b5bdbbb3958d03034aeb9ce 100644 (file)
@@ -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;
 }
index f45e87e8b91885bcc78e371a288891a35a357408..c04c77e5b40ea57947be26754ec3f2c088f683ac 100644 (file)
@@ -361,6 +361,8 @@ void InitVideoBuffer(int width, int height, int depth, boolean fullscreen)
 
   SDLInitVideoBuffer(&backbuffer, &window, fullscreen);
 
+  video.initialized = TRUE;
+
   drawto = backbuffer;
 }
 
index bb78fbe9453b442d666aa8b603b060f6ca327932..5050c72675af29cfb669f875e7c2fa192cd9f77f 100644 (file)
@@ -729,6 +729,8 @@ struct VideoSystemInfo
   boolean window_scaling_available;
   int window_scaling_percent;
   char *window_scaling_quality;
+
+  boolean initialized;
 };
 
 struct AudioSystemInfo