Merge pull request #2677 from phobos-tro/x11-memleak

X11 -- Fixing memleaks
This commit is contained in:
Okam Studio 2015-10-25 16:03:02 -03:00
commit 8949db75c3
3 changed files with 37 additions and 45 deletions

View file

@ -46,7 +46,6 @@ struct ContextGL_X11_Private {
::GLXContext glx_context; ::GLXContext glx_context;
}; };
void ContextGL_X11::release_current() { void ContextGL_X11::release_current() {
glXMakeCurrent(x11_display, None, NULL); glXMakeCurrent(x11_display, None, NULL);
@ -56,10 +55,12 @@ void ContextGL_X11::make_current() {
glXMakeCurrent(x11_display, x11_window, p->glx_context); glXMakeCurrent(x11_display, x11_window, p->glx_context);
} }
void ContextGL_X11::swap_buffers() { void ContextGL_X11::swap_buffers() {
glXSwapBuffers(x11_display,x11_window); glXSwapBuffers(x11_display,x11_window);
} }
/* /*
static GLWrapperFuncPtr wrapper_get_proc_address(const char* p_function) { static GLWrapperFuncPtr wrapper_get_proc_address(const char* p_function) {
@ -154,6 +155,9 @@ Error ContextGL_X11::initialize() {
*/ */
//glXMakeCurrent(x11_display, None, NULL); //glXMakeCurrent(x11_display, None, NULL);
XFree( vi );
XFree( fbc );
return OK; return OK;
} }
@ -164,12 +168,12 @@ int ContextGL_X11::get_window_width() {
return xwa.width; return xwa.width;
} }
int ContextGL_X11::get_window_height() { int ContextGL_X11::get_window_height() {
XWindowAttributes xwa; XWindowAttributes xwa;
XGetWindowAttributes(x11_display,x11_window,&xwa); XGetWindowAttributes(x11_display,x11_window,&xwa);
return xwa.height; return xwa.height;
} }
@ -189,6 +193,8 @@ ContextGL_X11::ContextGL_X11(::Display *p_x11_display,::Window &p_x11_window,con
ContextGL_X11::~ContextGL_X11() { ContextGL_X11::~ContextGL_X11() {
release_current();
glXDestroyContext( x11_display, p->glx_context );
memdelete( p ); memdelete( p );
} }

View file

@ -73,20 +73,18 @@
#undef CursorShape #undef CursorShape
int OS_X11::get_video_driver_count() const { int OS_X11::get_video_driver_count() const {
return 1; return 1;
} }
const char * OS_X11::get_video_driver_name(int p_driver) const {
const char * OS_X11::get_video_driver_name(int p_driver) const {
return "GLES2"; return "GLES2";
} }
OS::VideoMode OS_X11::get_default_video_mode() const {
OS::VideoMode OS_X11::get_default_video_mode() const {
return OS::VideoMode(800,600,false); return OS::VideoMode(800,600,false);
} }
int OS_X11::get_audio_driver_count() const { int OS_X11::get_audio_driver_count() const {
return AudioDriverManagerSW::get_driver_count(); return AudioDriverManagerSW::get_driver_count();
} }
@ -153,6 +151,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
XFree (xim_styles); XFree (xim_styles);
} }
XFree( imvalret );
} }
/* /*
@ -256,7 +255,6 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
} }
#endif #endif
AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton();
audio_driver_index=p_audio_driver; audio_driver_index=p_audio_driver;
@ -351,6 +349,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
for(int i=0;i<CURSOR_MAX;i++) { for(int i=0;i<CURSOR_MAX;i++) {
cursors[i]=None; cursors[i]=None;
img[i]=NULL;
} }
current_cursor=CURSOR_ARROW; current_cursor=CURSOR_ARROW;
@ -379,16 +378,15 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
"question_arrow" "question_arrow"
}; };
XcursorImage *img = XcursorLibraryLoadImage(cursor_file[i],cursor_theme,cursor_size); img[i] = XcursorLibraryLoadImage(cursor_file[i],cursor_theme,cursor_size);
if (img) { if (img[i]) {
cursors[i]=XcursorImageLoadCursor(x11_display,img); cursors[i]=XcursorImageLoadCursor(x11_display,img[i]);
//print_line("found cursor: "+String(cursor_file[i])+" id "+itos(cursors[i])); //print_line("found cursor: "+String(cursor_file[i])+" id "+itos(cursors[i]));
} else { } else {
if (OS::is_stdout_verbose()) if (OS::is_stdout_verbose())
print_line("failed cursor: "+String(cursor_file[i])); print_line("failed cursor: "+String(cursor_file[i]));
} }
} }
} }
@ -437,14 +435,8 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
probe_joystick(); probe_joystick();
_ensure_data_dir(); _ensure_data_dir();
net_wm_icon = XInternAtom(x11_display, "_NET_WM_ICON", False);
//printf("got map notify\n");
} }
void OS_X11::finalize() { void OS_X11::finalize() {
if(main_loop) if(main_loop)
@ -476,15 +468,27 @@ void OS_X11::finalize() {
memdelete(input); memdelete(input);
XUnmapWindow( x11_display, x11_window );
XDestroyWindow( x11_display, x11_window );
#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) #if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED)
memdelete(context_gl); memdelete(context_gl);
#endif #endif
for(int i=0;i<CURSOR_MAX;i++) {
if( cursors[i] != None )
XFreeCursor( x11_display, cursors[i] );
if( img[i] != NULL )
XcursorImageDestroy( img[i] );
};
XDestroyIC( xic );
XCloseIM( xim );
XCloseDisplay(x11_display); XCloseDisplay(x11_display);
if (xmbstring) if (xmbstring)
memfree(xmbstring); memfree(xmbstring);
args.clear(); args.clear();
} }
@ -559,37 +563,29 @@ void OS_X11::warp_mouse_pos(const Point2& p_to) {
} }
OS::MouseMode OS_X11::get_mouse_mode() const { OS::MouseMode OS_X11::get_mouse_mode() const {
return mouse_mode; return mouse_mode;
} }
int OS_X11::get_mouse_button_state() const { int OS_X11::get_mouse_button_state() const {
return last_button_state; return last_button_state;
} }
Point2 OS_X11::get_mouse_pos() const { Point2 OS_X11::get_mouse_pos() const {
return last_mouse_pos; return last_mouse_pos;
} }
void OS_X11::set_window_title(const String& p_title) { void OS_X11::set_window_title(const String& p_title) {
XStoreName(x11_display,x11_window,p_title.utf8().get_data()); XStoreName(x11_display,x11_window,p_title.utf8().get_data());
} }
void OS_X11::set_video_mode(const VideoMode& p_video_mode,int p_screen) { void OS_X11::set_video_mode(const VideoMode& p_video_mode,int p_screen) {
} }
OS::VideoMode OS_X11::get_video_mode(int p_screen) const {
OS::VideoMode OS_X11::get_video_mode(int p_screen) const {
return current_videomode; return current_videomode;
} }
void OS_X11::get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen) const { void OS_X11::get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen) const {
} }
//#ifdef NEW_WM_API //#ifdef NEW_WM_API
@ -672,7 +668,6 @@ void OS_X11::set_current_screen(int p_screen) {
} }
Point2 OS_X11::get_screen_position(int p_screen) const { Point2 OS_X11::get_screen_position(int p_screen) const {
// Using Xinerama Extension // Using Xinerama Extension
int event_base, error_base; int event_base, error_base;
const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base); const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base);
@ -708,7 +703,6 @@ Size2 OS_X11::get_screen_size(int p_screen) const {
return size; return size;
} }
Point2 OS_X11::get_window_position() const { Point2 OS_X11::get_window_position() const {
int x,y; int x,y;
Window child; Window child;
@ -896,7 +890,6 @@ void OS_X11::set_window_maximized(bool p_enabled) {
current_videomode.height = xwa.height; current_videomode.height = xwa.height;
*/ */
maximized = p_enabled; maximized = p_enabled;
} }
bool OS_X11::is_window_maximized() const { bool OS_X11::is_window_maximized() const {
@ -993,7 +986,6 @@ unsigned int OS_X11::get_mouse_button_state(unsigned int p_x11_state) {
void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) { void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) {
// X11 functions don't know what const is // X11 functions don't know what const is
XKeyEvent *xkeyevent = p_event; XKeyEvent *xkeyevent = p_event;
@ -1158,8 +1150,6 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) {
//printf("key: %x\n",event.key.scancode); //printf("key: %x\n",event.key.scancode);
input->parse_input_event( event); input->parse_input_event( event);
} }
void OS_X11::process_xevents() { void OS_X11::process_xevents() {
@ -1861,7 +1851,6 @@ void OS_X11::set_cursor_shape(CursorShape p_shape) {
XDefineCursor(x11_display,x11_window,cursors[CURSOR_ARROW]); XDefineCursor(x11_display,x11_window,cursors[CURSOR_ARROW]);
} }
current_cursor=p_shape; current_cursor=p_shape;
} }
@ -1894,6 +1883,8 @@ void OS_X11::alert(const String& p_alert,const String& p_title) {
} }
void OS_X11::set_icon(const Image& p_icon) { void OS_X11::set_icon(const Image& p_icon) {
Atom net_wm_icon = XInternAtom(x11_display, "_NET_WM_ICON", False);
if (!p_icon.empty()) { if (!p_icon.empty()) {
Image img=p_icon; Image img=p_icon;
img.convert(Image::FORMAT_RGBA); img.convert(Image::FORMAT_RGBA);
@ -1926,7 +1917,6 @@ void OS_X11::set_icon(const Image& p_icon) {
XDeleteProperty(x11_display, x11_window, net_wm_icon); XDeleteProperty(x11_display, x11_window, net_wm_icon);
} }
XFlush(x11_display); XFlush(x11_display);
} }

View file

@ -119,6 +119,7 @@ class OS_X11 : public OS_Unix {
const char *cursor_theme; const char *cursor_theme;
int cursor_size; int cursor_size;
XcursorImage *img[CURSOR_MAX];
Cursor cursors[CURSOR_MAX]; Cursor cursors[CURSOR_MAX];
Cursor null_cursor; Cursor null_cursor;
CursorShape current_cursor; CursorShape current_cursor;
@ -155,12 +156,7 @@ class OS_X11 : public OS_Unix {
}; };
}; };
}; };
Atom net_wm_icon;
int joystick_count; int joystick_count;
Joystick joysticks[JOYSTICKS_MAX]; Joystick joysticks[JOYSTICKS_MAX];
int audio_driver_index; int audio_driver_index;