X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsdl.c;h=8b8720c320fcfe182b5bdbbb3958d03034aeb9ce;hb=6b8e0388206475c9fae364474c84624fa5a49599;hp=12b39d865e701d9c2bcc64026247c5f3a6630bd7;hpb=3ff2e8a0b5c27b99a9920bdf5ed82bc41bf40181;p=rocksndiamonds.git diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 12b39d86..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,22 +210,20 @@ boolean SDLSetNativeSurface(SDL_Surface **surface) SDL_Surface *SDLGetNativeSurface(SDL_Surface *surface) { - if (surface == NULL || - backbuffer == NULL || - backbuffer->surface == NULL) + SDL_Surface *new_surface; + + if (surface == NULL) return NULL; - return SDL_ConvertSurface(surface, backbuffer->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); -SDL_Surface *SDL_DisplayFormat(SDL_Surface *surface) -{ - if (surface == NULL || - backbuffer == NULL || - backbuffer->surface == NULL) - return NULL; + 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 @@ -231,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); @@ -248,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; } @@ -1338,7 +1348,7 @@ Pixel SDLGetPixel(Bitmap *src_bitmap, int x, int y) /* ========================================================================= */ /* The following functions were taken from the SGE library */ -/* (SDL Graphics Extension Library) by Anders Lindström */ +/* (SDL Graphics Extension Library) by Anders Lindström */ /* http://www.etek.chalmers.se/~e8cal1/sge/index.html */ /* ========================================================================= */