From 2935ccce5270f72f9de9bb2470bd7de3c6ab295e Mon Sep 17 00:00:00 2001 From: Bob Pendleton Date: Fri, 7 Mar 2008 17:20:37 +0000 Subject: [PATCH] more valgrind errors fixed. Plus I ran make indent which changed a few files. --- src/video/SDL_video.c | 5 +++ src/video/win32/SDL_win32events.c | 6 ++-- src/video/win32/SDL_win32keyboard.c | 19 +++++----- src/video/x11/SDL_x11events.c | 15 ++++---- src/video/x11/SDL_x11opengl.c | 21 +++++------ src/video/x11/SDL_x11video.c | 1 + src/video/x11/SDL_x11video.h | 1 + src/video/x11/SDL_x11window.c | 55 +++++++++++++---------------- 8 files changed, 64 insertions(+), 59 deletions(-) diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 7c779b22a..8ff62dd95 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -2190,6 +2190,11 @@ SDL_VideoQuit(void) 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); diff --git a/src/video/win32/SDL_win32events.c b/src/video/win32/SDL_win32events.c index 37ba34361..5f257136d 100644 --- a/src/video/win32/SDL_win32events.c +++ b/src/video/win32/SDL_win32events.c @@ -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 @@ static WPARAM 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 @@ RemapVKEY(WPARAM wParam, LPARAM lParam) /* 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; } } diff --git a/src/video/win32/SDL_win32keyboard.c b/src/video/win32/SDL_win32keyboard.c index e185ddf09..b050d89bc 100644 --- a/src/video/win32/SDL_win32keyboard.c +++ b/src/video/win32/SDL_win32keyboard.c @@ -53,18 +53,21 @@ WIN_InitKeyboard(_THIS) 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 , 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 , 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 , 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 , 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 @@ WIN_UpdateKeymap(int keyboard) /* 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); diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c index b17f63969..eddeee5d7 100644 --- a/src/video/x11/SDL_x11events.c +++ b/src/video/x11/SDL_x11events.c @@ -51,15 +51,14 @@ X11_DispatchEvent(_THIS) } 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; diff --git a/src/video/x11/SDL_x11opengl.c b/src/video/x11/SDL_x11opengl.c index 951d00307..11bf5f925 100644 --- a/src/video/x11/SDL_x11opengl.c +++ b/src/video/x11/SDL_x11opengl.c @@ -281,19 +281,19 @@ int 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 @@ X11_GL_DeleteContext(_THIS, SDL_GLContext context) GLXContext glx_context = (GLXContext) context; _this->gl_data->glXDestroyContext(display, glx_context); + XSync(display, False); } #endif /* SDL_VIDEO_OPENGL_GLX */ diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c index 2b1f38990..bec97f1a8 100644 --- a/src/video/x11/SDL_x11video.c +++ b/src/video/x11/SDL_x11video.c @@ -101,6 +101,7 @@ X11_DeleteDevice(SDL_VideoDevice * device) if (data->display) { XCloseDisplay(data->display); } + SDL_free(data->windowlist); SDL_free(device->driverdata); SDL_free(device); diff --git a/src/video/x11/SDL_x11video.h b/src/video/x11/SDL_x11video.h index 9bb087d2d..bbc6a1205 100644 --- a/src/video/x11/SDL_x11video.h +++ b/src/video/x11/SDL_x11video.h @@ -67,6 +67,7 @@ typedef struct SDL_VideoData BOOL dpms_enabled; int numwindows; SDL_WindowData **windowlist; + int windowlistlength; int mouse; int keyboard; Atom WM_DELETE_WINDOW; diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c index 591b05606..50f4b9645 100644 --- a/src/video/x11/SDL_x11window.c +++ b/src/video/x11/SDL_x11window.c @@ -34,8 +34,8 @@ SetupWindowData(_THIS, SDL_Window * window, Window w, BOOL created) 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 @@ SetupWindowData(_THIS, SDL_Window * window, Window w, BOOL created) 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 (index >= 0) { - windowlist[index] = data; + 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; - } - windowlist[numwindows++] = data; - videodata->numwindows = numwindows; - videodata->windowlist = windowlist; + windowlist = + (SDL_WindowData **) SDL_realloc(windowlist, + (numwindows + + 1) * sizeof(*windowlist)); + if (!windowlist) { + SDL_OutOfMemory(); + SDL_free(data); + return -1; + } + windowlist[numwindows] = data; + videodata->numwindows++; + videodata->windowlistlength++; + videodata->windowlist = windowlist; } /* Fill in the SDL window with the window data */ @@ -494,7 +488,7 @@ X11_CreateWindow(_THIS, SDL_Window * window) } 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 @@ X11_DestroyWindow(_THIS, SDL_Window * window) 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) {