Fixed bug 907 - SDL window restore SDL_VIDEORESIZE event issue... SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Fri, 30 Dec 2011 06:01:09 -0500
branchSDL-1.2
changeset 6124 f56b95794ac8
parent 6123 ce2493a9cefb
child 6125 760a3162e180
Fixed bug 907 - SDL window restore SDL_VIDEORESIZE event issue... cjj_009@yahoo.com 2009-12-14 20:32:35 PST I've been working on an SDL/OpenGL program, that among other things, must deal with resizing events in order to adjust the aspect ratio. It doesn't always seem to get the SDL_VIDEORESIZE event when it should, causing the aspect ratio to not be adjusted as needed. I've run it in debug mode and made these observations: *When it initially starts up, if I maximize the window, it receives the SDL_VIDEORESIZE event as needed. *If, after starting up the the application and maximizing the window, I then restore the window by double clicking the title bar, it does NOT receive the SDL_VIDEORESIZE event. *I can repeat the last two steps, and it will get continue to get the SDL_VIDEORESIZE on the maximize but not get one on the restore. *If I then do a slight adjustment to the width or height of the window, it will get the SDL_VIDEORESIZE event. *From then on, if I do restore operations to the window, the SDL_VIDEORESIZE event will be caught properly. See http://forums.libsdl.org/viewtopic.php?t=5291 for additional information. vgvgf 2010-03-28 15:15:16 PDT Proposed patch for SDL_resize.c The width and height values stored in SDL_VideoSurface are the sizes of the video surface when it was created. So, when the window is rezised back to its creation size, the following condition will make the SDL_PrivateResize function stop, and the video resize msg won't be queued. if ( ! SDL_VideoSurface || ((w == SDL_VideoSurface->w) && (h == SDL_VideoSurface->h)) ) { return(0); } Sam Lantinga 2011-12-30 02:59:51 PST I'm okay with applying this patch, but be aware that the expected response to a resize message is that you call SDL_SetVideoMode() again with the new mode. This signals SDL that you're expecting the new size, and there may be other problems if you don't do this.
src/events/SDL_resize.c
--- a/src/events/SDL_resize.c	Fri Dec 30 04:04:34 2011 -0500
+++ b/src/events/SDL_resize.c	Fri Dec 30 06:01:09 2011 -0500
@@ -41,19 +41,14 @@
 	SDL_Event events[32];
 
 	/* See if this event would change the video surface */
-	if ( !w || !h
-#ifndef __OS2__
-            || ((last_resize.w == w) && (last_resize.h == h))
-#endif
-    ) {
-		return(0);
+	if ( !w || !h ||
+	     (( last_resize.w == w ) && ( last_resize.h == h )) ||
+	     !SDL_VideoSurface ) {
+		 return(0);
 	}
-        last_resize.w = w;
-        last_resize.h = h;
-	if ( ! SDL_VideoSurface ||
-	     ((w == SDL_VideoSurface->w) && (h == SDL_VideoSurface->h)) ) {
-		return(0);
-	}
+	last_resize.w = w;
+	last_resize.h = h;
+
 	SDL_SetMouseRange(w, h);
 
 	/* Pull out all old resize events */