Fixed bug #398 SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Tue, 03 Jul 2007 09:39:09 +0000
branchSDL-1.2
changeset 3995 604321d3575e
parent 3994 720c59bd38ac
child 3996 5f463dddee36
Fixed bug #398 You can use SetColors() before the video mode has been set.
src/video/SDL_video.c
--- a/src/video/SDL_video.c	Tue Jul 03 09:22:57 2007 +0000
+++ b/src/video/SDL_video.c	Tue Jul 03 09:39:09 2007 +0000
@@ -1142,16 +1142,18 @@
 		       ncolors * sizeof(*colors));
 	}
 
-	vidpal = SDL_VideoSurface->format->palette;
-	if ( (screen == SDL_ShadowSurface) && vidpal ) {
-		/*
-		 * This is a shadow surface, and the physical
-		 * framebuffer is also indexed. Propagate the
-		 * changes to its logical palette so that
-		 * updates are always identity blits
-		 */
-		SDL_memcpy(vidpal->colors + firstcolor, colors,
-		       ncolors * sizeof(*colors));
+	if ( current_video && SDL_VideoSurface ) {
+		vidpal = SDL_VideoSurface->format->palette;
+		if ( (screen == SDL_ShadowSurface) && vidpal ) {
+			/*
+			 * This is a shadow surface, and the physical
+			 * framebuffer is also indexed. Propagate the
+			 * changes to its logical palette so that
+			 * updates are always identity blits
+			 */
+			SDL_memcpy(vidpal->colors + firstcolor, colors,
+			       ncolors * sizeof(*colors));
+		}
 	}
 	SDL_FormatChanged(screen);
 }
@@ -1244,13 +1246,13 @@
 	int gotall;
 	int palsize;
 
-	if ( ! current_video ) {
+	if ( !screen ) {
 		return 0;
 	}
-	if ( screen != SDL_PublicSurface ) {
+	if ( !current_video || screen != SDL_PublicSurface ) {
 		/* only screens have physical palettes */
 		which &= ~SDL_PHYSPAL;
-	} else if( (screen->flags & SDL_HWPALETTE) != SDL_HWPALETTE ) {
+	} else if ( (screen->flags & SDL_HWPALETTE) != SDL_HWPALETTE ) {
 		/* hardware palettes required for split colormaps */
 		which |= SDL_PHYSPAL | SDL_LOGPAL;
 	}
@@ -1283,16 +1285,14 @@
 		 * program's idea of what the screen looks like, but changes
 		 * its actual appearance.
 		 */
-		if(!video)
-			return gotall;	/* video not yet initialized */
-		if(!video->physpal && !(which & SDL_LOGPAL) ) {
+		if ( !video->physpal && !(which & SDL_LOGPAL) ) {
 			/* Lazy physical palette allocation */
 			int size;
 			SDL_Palette *pp = SDL_malloc(sizeof(*pp));
 			if ( !pp ) {
 				return 0;
 			}
-			current_video->physpal = pp;
+			video->physpal = pp;
 			pp->ncolors = pal->ncolors;
 			size = pp->ncolors * sizeof(SDL_Color);
 			pp->colors = SDL_malloc(size);