GNOME Bugzilla – Bug 655307
Fix resource leak on subsequent calls to clutter_stage_osx_realize
Last modified: 2011-07-29 12:58:52 UTC
Adds haveRealized flag to clutter stage, so that clutter_stage_osx_realize() can now be called multiple times without leaking views and windows. Patch is here: https://github.com/spatulasnout/clutter/commit/68c700d2d7cdb189dfccd715e28f686348a5d26b commit 68c700d2d7cdb189dfccd715e28f686348a5d26b Author: Kirk A. Baker <kbaker@camerabits.com> Date: Mon Jul 25 15:00:30 2011 -0700 clutter_stage_osx_realize() can now be called multiple times without leaking views and windows diff --git a/clutter/osx/clutter-stage-osx.c b/clutter/osx/clutter-stage-osx.c index 6754970..cc80e02 100644 --- a/clutter/osx/clutter-stage-osx.c +++ b/clutter/osx/clutter-stage-osx.c @@ -289,31 +289,34 @@ clutter_stage_osx_realize (ClutterStageWindow *stage_window) CLUTTER_NOTE (BACKEND, "[%p] realize", self); - backend_osx = CLUTTER_BACKEND_OSX (self->backend); - /* Call get_size - this will either get the geometry size (which - * before we create the window is set to 640x480), or if a size - * is set, it will get that. This lets you set a size on the - * stage before it's realized. - */ - clutter_actor_get_size (CLUTTER_ACTOR (self->wrapper), &width, &height); - self->requisition_width = width; - self->requisition_height= height; - - rect = NSMakeRect(0, 0, self->requisition_width, self->requisition_height); - - self->view = [[ClutterGLView alloc] - initWithFrame: rect - pixelFormat: backend_osx->pixel_format - stage: self]; - [self->view setOpenGLContext:backend_osx->context]; - - self->window = [[ClutterGLWindow alloc] - initWithView: self->view - UTF8Title: clutter_stage_get_title (CLUTTER_STAGE (self->wrapper)) - stage: self]; - /* looks better than positioning to 0,0 (bottom right) */ - [self->window center]; - + if (!self->haveRealized) + { + backend_osx = CLUTTER_BACKEND_OSX (self->backend); + /* Call get_size - this will either get the geometry size (which + * before we create the window is set to 640x480), or if a size + * is set, it will get that. This lets you set a size on the + * stage before it's realized. + */ + clutter_actor_get_size (CLUTTER_ACTOR (self->wrapper), &width, &height); + self->requisition_width = width; + self->requisition_height= height; + + rect = NSMakeRect(0, 0, self->requisition_width, self->requisition_height); + + self->view = [[ClutterGLView alloc] + initWithFrame: rect + pixelFormat: backend_osx->pixel_format + stage: self]; + [self->view setOpenGLContext:backend_osx->context]; + + self->window = [[ClutterGLWindow alloc] + initWithView: self->view + UTF8Title: clutter_stage_get_title (CLUTTER_STAGE (self->wrapper)) + stage: self]; + /* looks better than positioning to 0,0 (bottom right) */ + [self->window center]; + self->haveRealized = true; + } CLUTTER_NOTE (BACKEND, "Stage successfully realized"); CLUTTER_OSX_POOL_RELEASE(); @@ -338,6 +341,7 @@ clutter_stage_osx_unrealize (ClutterStageWindow *stage_window) self->view = NULL; self->window = NULL; + self->haveRealized = false; CLUTTER_OSX_POOL_RELEASE(); } @@ -578,6 +582,10 @@ _clutter_stage_osx_new (ClutterBackend *backend, self = g_object_new (CLUTTER_TYPE_STAGE_OSX, NULL); self->backend = backend; self->wrapper = wrapper; + self->isHiding = false; + self->haveRealized = false; + self->view = NULL; + self->window = NULL; return CLUTTER_STAGE_WINDOW(self); } diff --git a/clutter/osx/clutter-stage-osx.h b/clutter/osx/clutter-stage-osx.h index b68f4bd..45943d1 100644 --- a/clutter/osx/clutter-stage-osx.h +++ b/clutter/osx/clutter-stage-osx.h @@ -68,6 +68,7 @@ struct _ClutterStageOSX gboolean acceptFocus; gboolean isHiding; + gboolean haveRealized; gfloat scroll_pos_x; gfloat scroll_pos_y;
Created attachment 192873 [details] [review] osx: Avoid leaks in Stage::realize clutter_stage_osx_realize() can now be called multiple times without leaking views and windows.
thanks for the patch, it looks good to me. I've taken the liberty of reformatting the commit message to conform to our own style.
Attachment 192873 [details] pushed as 01fd673 - osx: Avoid leaks in Stage::realize