From: Pierre-Luc Beaudoin Date: Tue, 24 Mar 2009 17:21:18 +0000 (+0200) Subject: Fix Tile ref counting X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9976b53b3c7adc5803d7420d04fcd026ed1700de;p=libchamplain Fix Tile ref counting --- diff --git a/champlain/champlain-map.c b/champlain/champlain-map.c index 2931de9..f9dce4a 100644 --- a/champlain/champlain-map.c +++ b/champlain/champlain-map.c @@ -96,9 +96,8 @@ map_load_visible_tiles (Map *map, ChamplainView *view, ChamplainMapSource *sourc ClutterActor *group, *actor; actor = champlain_tile_get_actor (tile); group = champlain_zoom_level_get_actor (map->current_level); - champlain_zoom_level_remove_tile (map->current_level, tile); - g_object_unref (tile); clutter_container_remove_actor (CLUTTER_CONTAINER (group), actor); + champlain_zoom_level_remove_tile (map->current_level, tile); } } @@ -125,6 +124,7 @@ map_load_visible_tiles (Map *map, ChamplainView *view, ChamplainMapSource *sourc g_object_set (G_OBJECT (tile), "x", i, "y", j, NULL); champlain_map_source_get_tile (source, view, map->current_level, tile); champlain_zoom_level_add_tile (map->current_level, tile); + g_object_unref (tile); } } } diff --git a/champlain/champlain-tile.c b/champlain/champlain-tile.c index 99fe5fd..c7c2cb0 100644 --- a/champlain/champlain-tile.c +++ b/champlain/champlain-tile.c @@ -447,6 +447,9 @@ champlain_tile_set_actor (ChamplainTile *self, ClutterActor *actor) ChamplainTilePrivate *priv = GET_PRIVATE (self); + if (priv->actor != NULL) + g_object_unref (priv->actor); + priv->actor = g_object_ref (actor); g_object_notify (G_OBJECT (self), "actor"); } diff --git a/champlain/champlain-zoom-level.c b/champlain/champlain-zoom-level.c index c376893..4d0dedc 100644 --- a/champlain/champlain-zoom-level.c +++ b/champlain/champlain-zoom-level.c @@ -111,10 +111,19 @@ static void champlain_zoom_level_dispose (GObject *object) { //FIXME: Get rid of tiles here? + guint k; ChamplainZoomLevelPrivate *priv = GET_PRIVATE (object); + ChamplainZoomLevel *level = CHAMPLAIN_ZOOM_LEVEL (object); g_object_unref (priv->actor); + // Get rid of old tiles first + for (k = 0; k < champlain_zoom_level_tile_count (level); k++) + { + ChamplainTile *tile = champlain_zoom_level_get_nth_tile (level, k); + champlain_zoom_level_remove_tile (level, tile); + } + G_OBJECT_CLASS (champlain_zoom_level_parent_class)->dispose (object); } @@ -208,6 +217,7 @@ champlain_zoom_level_add_tile (ChamplainZoomLevel *self, ChamplainZoomLevelPrivate *priv = GET_PRIVATE (self); + g_object_ref (tile); g_ptr_array_add (priv->tiles, tile); g_signal_emit (self, signals[SIGNAL_TILE_ADDED], 0, tile); } @@ -222,6 +232,7 @@ champlain_zoom_level_remove_tile (ChamplainZoomLevel *self, g_signal_emit (self, signals[SIGNAL_TILE_REMOVED], 0, tile); g_ptr_array_remove_fast (priv->tiles, tile); + g_object_unref (tile); } guint