From 26c7103750b3578561140b522fcc7e77ccd1ab0b Mon Sep 17 00:00:00 2001 From: George Matsumura Date: Wed, 19 Aug 2020 15:41:02 -0600 Subject: cogl: Fix reference counting bugs Signed-off-by: George Matsumura --- boilerplate/cairo-boilerplate-cogl.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'boilerplate') diff --git a/boilerplate/cairo-boilerplate-cogl.c b/boilerplate/cairo-boilerplate-cogl.c index 68ee5bd5d..c293b3932 100644 --- a/boilerplate/cairo-boilerplate-cogl.c +++ b/boilerplate/cairo-boilerplate-cogl.c @@ -78,6 +78,9 @@ _cairo_boilerplate_cogl_create_offscreen_color_surface (const char *name, device = cairo_cogl_device_create (context); + /* The device will take a reference on the context */ + cogl_object_unref (context); + closure = _cairo_malloc (sizeof (cogl_closure_t)); *abstract_closure = closure; closure->device = device; @@ -124,19 +127,31 @@ _cairo_boilerplate_cogl_create_onscreen_color_surface (const char *name, CoglDisplay *display; swap_chain = cogl_swap_chain_new (); - cogl_swap_chain_set_has_alpha (swap_chain, TRUE); + cogl_swap_chain_set_has_alpha (swap_chain, TRUE); onscreen_template = cogl_onscreen_template_new (swap_chain); renderer = cogl_renderer_new (); display = cogl_display_new (renderer, onscreen_template); + /* References will be taken on the swap chain, renderer, and + * onscreen template by the constructors */ + cogl_object_unref (swap_chain); + cogl_object_unref (renderer); + cogl_object_unref (onscreen_template); + context = cogl_context_new (display, NULL); - } else { + + /* The context will take a reference on the display */ + cogl_object_unref (display); + } else { context = cogl_context_new (NULL, NULL); } device = cairo_cogl_device_create (context); + /* The device will take a reference on the context */ + cogl_object_unref (context); + closure = _cairo_malloc (sizeof (cogl_closure_t)); *abstract_closure = closure; closure->device = device; -- cgit v1.2.1