Fixing memory leaks

This commit is contained in:
Phobos Tro 2015-10-25 22:15:56 +08:00
parent 4baf65dab7
commit 746ef7cbd6
3 changed files with 33 additions and 17 deletions

View File

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

View File

@ -153,6 +153,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
XFree (xim_styles);
}
XFree( imvalret );
}
/*
@ -351,6 +352,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
for(int i=0;i<CURSOR_MAX;i++) {
cursors[i]=None;
img[i]=NULL;
}
current_cursor=CURSOR_ARROW;
@ -379,16 +381,15 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
"question_arrow"
};
XcursorImage *img = XcursorLibraryLoadImage(cursor_file[i],cursor_theme,cursor_size);
if (img) {
cursors[i]=XcursorImageLoadCursor(x11_display,img);
img[i] = XcursorLibraryLoadImage(cursor_file[i],cursor_theme,cursor_size);
if (img[i]) {
cursors[i]=XcursorImageLoadCursor(x11_display,img[i]);
//print_line("found cursor: "+String(cursor_file[i])+" id "+itos(cursors[i]));
} else {
if (OS::is_stdout_verbose())
print_line("failed cursor: "+String(cursor_file[i]));
}
}
}
@ -438,13 +439,8 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
_ensure_data_dir();
net_wm_icon = XInternAtom(x11_display, "_NET_WM_ICON", False);
//printf("got map notify\n");
}
void OS_X11::finalize() {
if(main_loop)
@ -476,15 +472,27 @@ void OS_X11::finalize() {
memdelete(input);
XUnmapWindow( x11_display, x11_window );
XDestroyWindow( x11_display, x11_window );
#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED)
memdelete(context_gl);
#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);
if (xmbstring)
memfree(xmbstring);
args.clear();
}
@ -1861,7 +1869,6 @@ void OS_X11::set_cursor_shape(CursorShape p_shape) {
XDefineCursor(x11_display,x11_window,cursors[CURSOR_ARROW]);
}
current_cursor=p_shape;
}
@ -1894,6 +1901,8 @@ void OS_X11::alert(const String& p_alert,const String& p_title) {
}
void OS_X11::set_icon(const Image& p_icon) {
net_wm_icon = XInternAtom(x11_display, "_NET_WM_ICON", False);
if (!p_icon.empty()) {
Image img=p_icon;
img.convert(Image::FORMAT_RGBA);

View File

@ -119,6 +119,7 @@ class OS_X11 : public OS_Unix {
const char *cursor_theme;
int cursor_size;
XcursorImage *img[CURSOR_MAX];
Cursor cursors[CURSOR_MAX];
Cursor null_cursor;
CursorShape current_cursor;