diff src/video/SDL_video.c @ 1667:1fddae038bc8 SDL-1.3

Implemented many compatibility functions
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 03:53:21 +0000
parents 6e7ec5cb83c3
children 4da1ee79c9af
line wrap: on
line diff
--- a/src/video/SDL_video.c	Sun May 28 21:56:07 2006 +0000
+++ b/src/video/SDL_video.c	Mon May 29 03:53:21 2006 +0000
@@ -512,7 +512,9 @@
 int
 SDL_SetDisplayMode (const SDL_DisplayMode * mode)
 {
+    SDL_VideoDisplay *display;
     SDL_DisplayMode display_mode;
+    int i;
 
     if (!_this) {
         SDL_SetError ("Video subsystem has not been initialized");
@@ -524,21 +526,21 @@
         SDL_SetError ("No mode passed to SDL_SetDisplayMode");
         return -1;
     }
+    display = &SDL_CurrentDisplay;
     display_mode = *mode;
 
     /* Default to the current mode */
     if (!display_mode.format) {
-        display_mode.format = SDL_CurrentDisplay.current_mode.format;
+        display_mode.format = display->current_mode.format;
     }
     if (!display_mode.w) {
-        display_mode.w = SDL_CurrentDisplay.current_mode.w;
+        display_mode.w = display->current_mode.w;
     }
     if (!display_mode.h) {
-        display_mode.h = SDL_CurrentDisplay.current_mode.h;
+        display_mode.h = display->current_mode.h;
     }
     if (!display_mode.refresh_rate) {
-        display_mode.refresh_rate =
-            SDL_CurrentDisplay.current_mode.refresh_rate;
+        display_mode.refresh_rate = display->current_mode.refresh_rate;
     }
 
     /* Get a good video mode, the closest one possible */
@@ -555,6 +557,19 @@
         return 0;
     }
 
+    /* Free any previous window surfaces */
+    for (i = 0; i < display->num_windows; ++i) {
+        SDL_Window *window = &display->windows[i];
+        if (window->shadow) {
+            SDL_FreeSurface (window->shadow);
+            window->shadow = NULL;
+        }
+        if (window->surface) {
+            SDL_FreeSurface (window->surface);
+            window->surface = NULL;
+        }
+    }
+
     return _this->SetDisplayMode (_this, &display_mode);
 }
 
@@ -580,7 +595,7 @@
 
     SDL_zero (window);
     window.id = _this->next_window_id++;
-    window.title = SDL_strdup (title);
+    window.title = title ? SDL_strdup (title) : NULL;
     window.x = x;
     window.y = y;
     window.w = w;
@@ -588,7 +603,9 @@
     window.flags = (flags & allowed_flags);
 
     if (_this->CreateWindow && _this->CreateWindow (_this, &window) < 0) {
-        SDL_free (window.title);
+        if (window.title) {
+            SDL_free (window.title);
+        }
         return 0;
     }
 
@@ -600,7 +617,9 @@
         if (_this->DestroyWindow) {
             _this->DestroyWindow (_this, &window);
         }
-        SDL_free (window.title);
+        if (window.title) {
+            SDL_free (window.title);
+        }
         return 0;
     }
     windows[num_windows] = window;
@@ -638,7 +657,9 @@
         if (_this->DestroyWindow) {
             _this->DestroyWindow (_this, &window);
         }
-        SDL_free (window.title);
+        if (window.title) {
+            SDL_free (window.title);
+        }
         return 0;
     }
     windows[num_windows] = window;
@@ -674,7 +695,7 @@
 {
     int i, j;
 
-    if (!_this) {
+    if (!_this || !surface) {
         return NULL;
     }