comparison src/video/x11/SDL_x11window.c @ 2323:4ac07ae446d3

Fixed many valgrind errors. But, I broke testdyngl.
author Bob Pendleton <bob@pendleton.com>
date Thu, 06 Mar 2008 23:07:02 +0000
parents c25d45b7add3
children 3202e4826c57
comparison
equal deleted inserted replaced
2322:c25d45b7add3 2323:4ac07ae446d3
33 { 33 {
34 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; 34 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
35 SDL_WindowData *data; 35 SDL_WindowData *data;
36 int numwindows = videodata->numwindows; 36 int numwindows = videodata->numwindows;
37 SDL_WindowData **windowlist = videodata->windowlist; 37 SDL_WindowData **windowlist = videodata->windowlist;
38 int i;
39 int index;
38 40
39 /* Allocate the window data */ 41 /* Allocate the window data */
40 data = (SDL_WindowData *) SDL_malloc(sizeof(*data)); 42 data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
41 if (!data) { 43 if (!data) {
42 SDL_OutOfMemory(); 44 SDL_OutOfMemory();
43 return -1; 45 return -1;
44 } 46 }
45 data->windowID = window->id; 47 data->windowID = window->id;
53 videodata->classname, NULL); 55 videodata->classname, NULL);
54 } 56 }
55 #endif 57 #endif
56 data->created = created; 58 data->created = created;
57 data->videodata = videodata; 59 data->videodata = videodata;
60
61 /* Associate the data with the window */
62 index = -1;
63 if (windowlist) {
64 for (i = 0; i < numwindows; ++i) {
65 if (windowlist[i] == NULL) {
66 index = i;
67 break;
68 }
69 }
70 }
71
72 if (index >= 0) {
73 windowlist[index] = data;
74 } else {
75 windowlist =
76 (SDL_WindowData **) SDL_realloc(windowlist,
77 (numwindows + 1) * sizeof(*windowlist));
78 if (!windowlist) {
79 SDL_OutOfMemory();
80 SDL_free(data);
81 return -1;
82 }
83 windowlist[numwindows++] = data;
84 videodata->numwindows = numwindows;
85 videodata->windowlist = windowlist;
86 }
58 87
59 /* Fill in the SDL window with the window data */ 88 /* Fill in the SDL window with the window data */
60 { 89 {
61 XWindowAttributes attrib; 90 XWindowAttributes attrib;
62 91
456 if (window->flags & SDL_WINDOW_OPENGL) { 485 if (window->flags & SDL_WINDOW_OPENGL) {
457 X11_GL_Shutdown(_this); 486 X11_GL_Shutdown(_this);
458 } 487 }
459 #endif 488 #endif
460 XDestroyWindow(data->display, w); 489 XDestroyWindow(data->display, w);
490 X11_PumpEvents(_this);
461 return -1; 491 return -1;
462 } 492 }
463 return 0; 493 return 0;
464 } 494 }
465 495
623 653
624 void 654 void
625 X11_DestroyWindow(_THIS, SDL_Window * window) 655 X11_DestroyWindow(_THIS, SDL_Window * window)
626 { 656 {
627 SDL_WindowData *data = (SDL_WindowData *) window->driverdata; 657 SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
658 window->driverdata = NULL;
628 659
629 if (data) { 660 if (data) {
630 Display *display = data->videodata->display; 661 SDL_VideoData *videodata = (SDL_VideoData *) data->videodata;
662 Display *display = videodata->display;
663 int numwindows = videodata->numwindows;
664 SDL_WindowData **windowlist = videodata->windowlist;
665 int i;
666
667 if (windowlist) {
668 for (i = 0; i < numwindows; ++i) {
669 if (windowlist[i] &&
670 (windowlist[i]->windowID == window->id)) {
671 windowlist[i] = NULL;
672 break;
673 }
674 }
675 }
631 #ifdef SDL_VIDEO_OPENGL_GLX 676 #ifdef SDL_VIDEO_OPENGL_GLX
632 if (window->flags & SDL_WINDOW_OPENGL) { 677 if (window->flags & SDL_WINDOW_OPENGL) {
633 X11_GL_Shutdown(_this); 678 X11_GL_Shutdown(_this);
634 } 679 }
635 #endif 680 #endif
638 XDestroyIC(data->ic); 683 XDestroyIC(data->ic);
639 } 684 }
640 #endif 685 #endif
641 if (data->created) { 686 if (data->created) {
642 XDestroyWindow(display, data->window); 687 XDestroyWindow(display, data->window);
688 X11_PumpEvents(_this);
643 } 689 }
644 SDL_free(data); 690 SDL_free(data);
645 window->driverdata = NULL;
646 } 691 }
647 } 692 }
648 693
649 SDL_bool 694 SDL_bool
650 X11_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info) 695 X11_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)