From: Pierre-Luc Beaudoin Date: Thu, 4 Sep 2008 23:08:32 +0000 (-0400) Subject: Fix async free of tiles X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=671e2383e2a05d4b6100136062faa1d1893b2ab1;p=libchamplain Fix async free of tiles --- diff --git a/champlain/champlainview.c b/champlain/champlainview.c index e9e9c79..785aae6 100644 --- a/champlain/champlainview.c +++ b/champlain/champlainview.c @@ -411,15 +411,13 @@ viewport_x_changed_cb(GObject *gobject, GParamSpec *arg1, ChamplainView *champla { ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (champlainView); - GdkRectangle rect; + GdkPoint rect; tidy_viewport_get_origin(TIDY_VIEWPORT(priv->viewport), &rect.x, &rect.y, NULL); if (rect.x < 0 || rect.y < 0) return; - /*if (rect.x == priv->viewportSize.x && - rect.y == priv->viewportSize.y && - rect.width == priv->viewportSize.width && - rect.height == priv->viewportSize.height) - return;*/ + if (rect.x == priv->viewportSize.x && + rect.y == priv->viewportSize.y) + return; priv->viewportSize.x = rect.x; priv->viewportSize.y = rect.y; diff --git a/champlain/tile.c b/champlain/tile.c index 01f9296..67ee736 100644 --- a/champlain/tile.c +++ b/champlain/tile.c @@ -33,7 +33,8 @@ typedef struct { } TwoPtr; #define CACHE_DIR "champlain" - +static SoupSession * soup_session; + void tile_set(Map* map, Tile* tile) { @@ -123,11 +124,22 @@ file_loaded_cb (SoupSession *session, map->name, map_filename, NULL); - + + g_print("Writing %s\n", map_filename); g_file_set_contents (filename, msg->response_body->data, msg->response_body->length, NULL); + // If the tile has been marked to be deleted, don't go any further + if(tile->to_destroy) + { + g_object_unref (loader); + g_free (filename); + g_free (map_filename); + g_free (tile); + return; + } + GdkPixbuf* pixbuf = gdk_pixbuf_loader_get_pixbuf(loader); tile->actor = clutter_texture_new(); @@ -143,6 +155,8 @@ file_loaded_cb (SoupSession *session, clutter_container_add (CLUTTER_CONTAINER (map->current_level->group), tile->actor, NULL); + tile->loading = FALSE; + g_object_unref (loader); g_free (filename); g_free (map_filename); @@ -152,10 +166,10 @@ file_loaded_cb (SoupSession *session, Tile* tile_load (Map* map, guint zoom_level, guint x, guint y, gboolean offline) { - static SoupSession * session; gchar* filename, *map_filename; Tile* tile = g_new0(Tile, 1); - + g_print ("Tile %d, %d\n", x, y); + tile->x = x; tile->y = y; tile->level = zoom_level; @@ -183,14 +197,15 @@ tile_load (Map* map, guint zoom_level, guint x, guint y, gboolean offline) else if (!offline) { SoupMessage *msg; - if (!session) - session = soup_session_async_new (); + if (!soup_session) + soup_session = soup_session_async_new (); msg = soup_message_new (SOUP_METHOD_GET, map->get_tile_uri(map, tile)); - soup_session_queue_message (session, msg, + soup_session_queue_message (soup_session, msg, file_loaded_cb, ptr); + tile->loading = TRUE; } // If a tile is neither in cache or can be fetched, do nothing, it'll show up as empty @@ -205,5 +220,8 @@ tile_free(Tile* tile) { if(tile->actor) clutter_actor_destroy(tile->actor); - g_free(tile); + if(tile->loading) + tile->to_destroy = TRUE; + else + g_free(tile); } diff --git a/champlain/tile.h b/champlain/tile.h index 1fc321a..16b3b8d 100644 --- a/champlain/tile.h +++ b/champlain/tile.h @@ -31,6 +31,9 @@ typedef struct int size; int level; + gboolean loading; // TRUE when a callback exist to load the tile, FALSE otherwise + gboolean to_destroy; // TRUE when a tile struct should be deleted when loading is done, FALSE otherwise + } Tile; void tile_free(Tile* tile);