Mercurial > sdl-ios-xcode
diff src/video/x11/SDL_x11window.c @ 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 |
line wrap: on
line diff
--- 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) {