changeset 2324:3202e4826c57

more valgrind errors fixed. Plus I ran make indent which changed a few files.
author Bob Pendleton <bob@pendleton.com>
date Fri, 07 Mar 2008 17:20:37 +0000
parents 4ac07ae446d3
children c7bcf84ba1b9
files src/video/SDL_video.c src/video/win32/SDL_win32events.c src/video/win32/SDL_win32keyboard.c src/video/x11/SDL_x11events.c src/video/x11/SDL_x11opengl.c src/video/x11/SDL_x11video.c src/video/x11/SDL_x11video.h src/video/x11/SDL_x11window.c
diffstat 8 files changed, 65 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/SDL_video.c	Thu Mar 06 23:07:02 2008 +0000
+++ b/src/video/SDL_video.c	Fri Mar 07 17:20:37 2008 +0000
@@ -2190,6 +2190,11 @@
             display->windows = NULL;
         }
         display->num_windows = 0;
+        if (display->render_drivers) {
+            SDL_free(display->render_drivers);
+            display->render_drivers = NULL;
+        }
+        display->num_render_drivers = 0;
     }
     _this->VideoQuit(_this);
 
--- a/src/video/win32/SDL_win32events.c	Thu Mar 06 23:07:02 2008 +0000
+++ b/src/video/win32/SDL_win32events.c	Fri Mar 07 17:20:37 2008 +0000
@@ -36,7 +36,7 @@
 #define REPEATED_KEYMASK    (1<<30)
 #define EXTENDED_KEYMASK    (1<<24)
 
-#define VK_ENTER    10  /* Keypad Enter ... no VKEY defined? */
+#define VK_ENTER    10          /* Keypad Enter ... no VKEY defined? */
 
 /* Make sure XBUTTON stuff is defined that isn't in older Platform SDKs... */
 #ifndef WM_XBUTTONDOWN
@@ -53,7 +53,7 @@
 RemapVKEY(WPARAM wParam, LPARAM lParam)
 {
     int i;
-    BYTE scancode = (BYTE)((lParam >> 16) & 0xFF);
+    BYTE scancode = (BYTE) ((lParam >> 16) & 0xFF);
 
     /* Windows remaps alphabetic keys based on current layout.
        We try to provide USB scancodes, so undo this mapping.
@@ -72,7 +72,7 @@
     /* Keypad keys are a little trickier, we always scan for them. */
     for (i = 0; i < SDL_arraysize(keypad_scancodes); ++i) {
         if (scancode == keypad_scancodes[i]) {
-            wParam = VK_NUMPAD0+i;
+            wParam = VK_NUMPAD0 + i;
             break;
         }
     }
--- a/src/video/win32/SDL_win32keyboard.c	Thu Mar 06 23:07:02 2008 +0000
+++ b/src/video/win32/SDL_win32keyboard.c	Fri Mar 07 17:20:37 2008 +0000
@@ -53,18 +53,21 @@
     int i;
 
     /* Make sure the alpha scancodes are correct.  T isn't usually remapped */
-    if (MapVirtualKey('T', MAPVK_VK_TO_VSC) != alpha_scancodes['T'-'A']) {
-printf("Fixing alpha scancode map, assuming US QWERTY layout!\nPlease send the following 26 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n");
+    if (MapVirtualKey('T', MAPVK_VK_TO_VSC) != alpha_scancodes['T' - 'A']) {
+        printf
+            ("Fixing alpha scancode map, assuming US QWERTY layout!\nPlease send the following 26 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n");
         for (i = 0; i < SDL_arraysize(alpha_scancodes); ++i) {
-            alpha_scancodes[i] = MapVirtualKey('A'+i, MAPVK_VK_TO_VSC);
-printf("%d = %d\n", i, alpha_scancodes[i]);
+            alpha_scancodes[i] = MapVirtualKey('A' + i, MAPVK_VK_TO_VSC);
+            printf("%d = %d\n", i, alpha_scancodes[i]);
         }
     }
     if (MapVirtualKey(VK_NUMPAD0, MAPVK_VK_TO_VSC) != keypad_scancodes[0]) {
-printf("Fixing keypad scancode map!\nPlease send the following 10 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n");
+        printf
+            ("Fixing keypad scancode map!\nPlease send the following 10 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n");
         for (i = 0; i < SDL_arraysize(keypad_scancodes); ++i) {
-            keypad_scancodes[i] = MapVirtualKey(VK_NUMPAD0+i, MAPVK_VK_TO_VSC);
-printf("%d = %d\n", i, keypad_scancodes[i]);
+            keypad_scancodes[i] =
+                MapVirtualKey(VK_NUMPAD0 + i, MAPVK_VK_TO_VSC);
+            printf("%d = %d\n", i, keypad_scancodes[i]);
         }
     }
 
@@ -99,7 +102,7 @@
 
         /* Alphabetic keys are handled specially, since Windows remaps them */
         if (i >= 'A' && i <= 'Z') {
-            BYTE vsc = alpha_scancodes[i-'A'];
+            BYTE vsc = alpha_scancodes[i - 'A'];
             keymap[scancode] = MapVirtualKey(vsc, MAPVK_VSC_TO_VK) + 0x20;
         } else {
             keymap[scancode] = (MapVirtualKey(i, MAPVK_VK_TO_CHAR) & 0x7FFF);
--- a/src/video/x11/SDL_x11events.c	Thu Mar 06 23:07:02 2008 +0000
+++ b/src/video/x11/SDL_x11events.c	Fri Mar 07 17:20:37 2008 +0000
@@ -51,15 +51,14 @@
     }
 
     data = NULL;
-    if (videodata && 
-        videodata->windowlist) {
-      for (i = 0; i < videodata->numwindows; ++i) {
-        if ((videodata->windowlist[i] != NULL) &&
-            (videodata->windowlist[i]->window == xevent.xany.window)) {
-          data = videodata->windowlist[i];
-          break;
+    if (videodata && videodata->windowlist) {
+        for (i = 0; i < videodata->numwindows; ++i) {
+            if ((videodata->windowlist[i] != NULL) &&
+                (videodata->windowlist[i]->window == xevent.xany.window)) {
+                data = videodata->windowlist[i];
+                break;
+            }
         }
-      }
     }
     if (!data) {
         return;
--- a/src/video/x11/SDL_x11opengl.c	Thu Mar 06 23:07:02 2008 +0000
+++ b/src/video/x11/SDL_x11opengl.c	Fri Mar 07 17:20:37 2008 +0000
@@ -281,19 +281,19 @@
 X11_GL_Initialize(_THIS)
 {
 
-  if (X11_GL_InitializeMemory(_this) < 0) {
-     return -1;
-  }
-  ++_this->gl_data->initialized;
+    if (X11_GL_InitializeMemory(_this) < 0) {
+        return -1;
+    }
+    ++_this->gl_data->initialized;
 
-  if (X11_GL_LoadLibrary(_this, NULL) < 0) {
-    return -1;
-  }
+    if (X11_GL_LoadLibrary(_this, NULL) < 0) {
+        return -1;
+    }
 
-  /* Initialize extensions */
-  X11_GL_InitExtensions(_this);
+    /* Initialize extensions */
+    X11_GL_InitExtensions(_this);
 
-  return 0;
+    return 0;
 }
 
 void
@@ -523,6 +523,7 @@
     GLXContext glx_context = (GLXContext) context;
 
     _this->gl_data->glXDestroyContext(display, glx_context);
+    XSync(display, False);
 }
 
 #endif /* SDL_VIDEO_OPENGL_GLX */
--- a/src/video/x11/SDL_x11video.c	Thu Mar 06 23:07:02 2008 +0000
+++ b/src/video/x11/SDL_x11video.c	Fri Mar 07 17:20:37 2008 +0000
@@ -101,6 +101,7 @@
     if (data->display) {
         XCloseDisplay(data->display);
     }
+    SDL_free(data->windowlist);
     SDL_free(device->driverdata);
     SDL_free(device);
 
--- a/src/video/x11/SDL_x11video.h	Thu Mar 06 23:07:02 2008 +0000
+++ b/src/video/x11/SDL_x11video.h	Fri Mar 07 17:20:37 2008 +0000
@@ -67,6 +67,7 @@
     BOOL dpms_enabled;
     int numwindows;
     SDL_WindowData **windowlist;
+    int windowlistlength;
     int mouse;
     int keyboard;
     Atom WM_DELETE_WINDOW;
--- a/src/video/x11/SDL_x11window.c	Thu Mar 06 23:07:02 2008 +0000
+++ b/src/video/x11/SDL_x11window.c	Fri Mar 07 17:20:37 2008 +0000
@@ -34,8 +34,8 @@
     SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
     SDL_WindowData *data;
     int numwindows = videodata->numwindows;
+    int windowlistlength = videodata->windowlistlength;
     SDL_WindowData **windowlist = videodata->windowlist;
-    int i;
     int index;
 
     /* Allocate the window data */
@@ -59,30 +59,24 @@
     data->videodata = videodata;
 
     /* Associate the data with the window */
-    index = -1;
-    if (windowlist) {
-      for (i = 0; i < numwindows; ++i) {
-        if (windowlist[i] == NULL) {
-          index = i;
-          break;
+
+    if (numwindows < windowlistlength) {
+        windowlist[numwindows] = data;
+        videodata->numwindows++;
+    } else {
+        windowlist =
+            (SDL_WindowData **) SDL_realloc(windowlist,
+                                            (numwindows +
+                                             1) * sizeof(*windowlist));
+        if (!windowlist) {
+            SDL_OutOfMemory();
+            SDL_free(data);
+            return -1;
         }
-      }
-    }
-
-    if (index >= 0) {
-      windowlist[index] = data;
-    } else {
-      windowlist =
-      (SDL_WindowData **) SDL_realloc(windowlist,
-                                      (numwindows + 1) * sizeof(*windowlist));
-      if (!windowlist) {
-        SDL_OutOfMemory();
-        SDL_free(data);
-        return -1;
-      }
-      windowlist[numwindows++] = data;
-      videodata->numwindows = numwindows;
-      videodata->windowlist = windowlist;
+        windowlist[numwindows] = data;
+        videodata->numwindows++;
+        videodata->windowlistlength++;
+        videodata->windowlist = windowlist;
     }
 
     /* Fill in the SDL window with the window data */
@@ -494,7 +488,7 @@
 }
 
 int
-X11_CreateWindowFrom(_THIS, SDL_Window *window, const void *data)
+X11_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
 {
     Window w = (Window) data;
 
@@ -665,13 +659,14 @@
         int i;
 
         if (windowlist) {
-          for (i = 0; i < numwindows; ++i) {
-            if (windowlist[i] && 
-                (windowlist[i]->windowID == window->id)) {
-              windowlist[i] = NULL;
-              break;
+            for (i = 0; i < numwindows; ++i) {
+                if (windowlist[i] && (windowlist[i]->windowID == window->id)) {
+                    windowlist[i] = windowlist[numwindows - 1];
+                    windowlist[numwindows - 1] = NULL;
+                    videodata->numwindows--;
+                    break;
+                }
             }
-          }
         }
 #ifdef SDL_VIDEO_OPENGL_GLX
         if (window->flags & SDL_WINDOW_OPENGL) {