More reference counting updates
authorAndy Spencer <andy753421@gmail.com>
Wed, 26 Dec 2012 23:39:12 +0000 (23:39 +0000)
committerAndy Spencer <andy753421@gmail.com>
Wed, 26 Dec 2012 23:39:12 +0000 (23:39 +0000)
The viewer now adds it's own references and doesn't take references from
the caller. In almost all cases the caller needs to keep it's reference
so that it can remove the object when the plugin is unloaded.

src/grits-opengl.c
src/grits-plugin.c
src/grits-viewer.c
src/objects/grits-callback.c
src/plugins/elev.c
src/plugins/env.c
src/plugins/map.c
src/plugins/sat.c
src/plugins/test.c

index 49a9c53..a17ddda 100644 (file)
@@ -618,6 +618,7 @@ static void grits_opengl_add(GritsViewer *_opengl, GritsObject *object,
                list->next->prev = link;
        list->next = link;
        object->ref = link;
+       g_object_ref(object);
        g_mutex_unlock(&opengl->objects_lock);
 }
 
@@ -625,6 +626,8 @@ void grits_opengl_remove(GritsViewer *_opengl, GritsObject *object)
 {
        g_assert(GRITS_IS_OPENGL(_opengl));
        GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
+       if (!object->ref)
+               return;
        g_mutex_lock(&opengl->objects_lock);
        GList *link = object->ref;
        /* Just unlink and free it, link->prev is assured */
@@ -632,6 +635,8 @@ void grits_opengl_remove(GritsViewer *_opengl, GritsObject *object)
        if (link->next)
                link->next->prev = link->prev;
        g_free(link);
+       object->ref = NULL;
+       g_object_unref(object);
        g_mutex_unlock(&opengl->objects_lock);
 }
 
index d79fdd1..60b3bbd 100644 (file)
@@ -171,7 +171,7 @@ void grits_plugins_free(GritsPlugins *plugins)
        g_debug("GritsPlugins: free");
        for (GList *cur = plugins->plugins; cur; cur = cur->next) {
                GritsPluginStore *store = cur->data;
-               g_debug("GritsPlugin: freeing %s refs=%d->%d", store->name,
+               g_debug("GritsPlugins: freeing %s refs=%d->%d", store->name,
                        G_OBJECT(store->plugin)->ref_count,
                        G_OBJECT(store->plugin)->ref_count-1);
                grits_plugins_free_store(store);
index 52fbaf9..aa5c3a5 100644 (file)
@@ -565,7 +565,6 @@ void grits_viewer_add(GritsViewer *viewer, GritsObject *object,
  * @object: the object to remove
  *
  * Remove an object from the viewer.
- * The objects reference count is decremented.
  */
 void grits_viewer_remove(GritsViewer *viewer, GritsObject *object)
 {
@@ -576,7 +575,6 @@ void grits_viewer_remove(GritsViewer *viewer, GritsObject *object)
                g_warning("GritsViewer: remove - Unimplemented");
        object->viewer = NULL;
        klass->remove(viewer, object);
-       g_object_unref(object);
 }
 
 /****************
index 36ba3af..2532c99 100644 (file)
@@ -60,6 +60,7 @@ G_DEFINE_TYPE(GritsCallback, grits_callback, GRITS_TYPE_OBJECT);
 static void grits_callback_finalize(GObject *cb)
 {
        g_debug("GritsCallback: finalize");
+       G_OBJECT_CLASS(grits_callback_parent_class)->finalize(cb);
 }
 static void grits_callback_init(GritsCallback *cb)
 {
index 7540a08..db7b977 100644 (file)
@@ -343,8 +343,7 @@ static void grits_plugin_elev_dispose(GObject *gobject)
                        grits_viewer_clear_height_func(viewer);
                if (LOAD_TEX)
                        grits_viewer_remove(viewer, GRITS_OBJECT(elev->tiles));
-               else
-                       g_object_unref(elev->tiles);
+               g_object_unref(elev->tiles);
                soup_session_abort(elev->wms->http->soup);
                g_thread_pool_free(elev->threads, TRUE, TRUE);
                while (gtk_events_pending())
index d833b43..6312f3b 100644 (file)
@@ -376,7 +376,7 @@ static void grits_plugin_env_dispose(GObject *gobject)
        if (env->viewer) {
                for (GList *cur = env->refs; cur; cur = cur->next)
                        grits_viewer_remove(env->viewer, cur->data);
-               g_list_free(env->refs);
+               g_list_free_full(env->refs, g_object_unref);
                g_object_unref(env->viewer);
                g_object_unref(env->prefs);
                glDeleteTextures(1, &env->tex);
index bb585e1..13f986c 100644 (file)
@@ -248,6 +248,7 @@ static void grits_plugin_map_dispose(GObject *gobject)
                map->viewer = NULL;
                g_signal_handler_disconnect(viewer, map->sigid);
                grits_viewer_remove(viewer, GRITS_OBJECT(map->tiles));
+               g_object_unref(map->tiles);
                soup_session_abort(map->tms->http->soup);
                //soup_session_abort(map->wms->http->soup);
                g_thread_pool_free(map->threads, TRUE, TRUE);
index d9d0891..8fe6e09 100644 (file)
@@ -226,6 +226,7 @@ static void grits_plugin_sat_dispose(GObject *gobject)
                sat->viewer = NULL;
                g_signal_handler_disconnect(viewer, sat->sigid);
                grits_viewer_remove(viewer, GRITS_OBJECT(sat->tiles));
+               g_object_unref(sat->tiles);
                soup_session_abort(sat->wms->http->soup);
                g_thread_pool_free(sat->threads, TRUE, TRUE);
                while (gtk_events_pending())
index 8a7e8a6..cfc999b 100644 (file)
@@ -180,6 +180,9 @@ static void grits_plugin_test_dispose(GObject *_test)
                grits_viewer_remove(viewer, GRITS_OBJECT(test->marker));
                grits_viewer_remove(viewer, GRITS_OBJECT(test->poly));
                grits_viewer_remove(viewer, GRITS_OBJECT(test->line));
+               g_object_unref(test->marker);
+               g_object_unref(test->poly);
+               g_object_unref(test->line);
                g_object_unref(viewer);
        }
        G_OBJECT_CLASS(grits_plugin_test_parent_class)->dispose(_test);