]> err.no Git - libchamplain/commitdiff
Fix async free of tiles
authorPierre-Luc Beaudoin <pierre-luc@squidy.info>
Thu, 4 Sep 2008 23:08:32 +0000 (19:08 -0400)
committerPierre-Luc Beaudoin <pierre-luc@squidy.info>
Thu, 4 Sep 2008 23:08:32 +0000 (19:08 -0400)
champlain/champlainview.c
champlain/tile.c
champlain/tile.h

index e9e9c79e86cd3c52f6bbb958125dad150d2d1d63..785aae61b0b88b7c214c324266487f83fa0a7e53 100644 (file)
@@ -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;
index 01f92969c0ad2f3abb99e217adc4d6c1be0721bb..67ee736aebef32edf421c6c47f8ab8b416ccc9d5 100644 (file)
@@ -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);
 }
index 1fc321a13cf14c99218ff2e71718a3345be6ace9..16b3b8d74b4cfc8c14da16f22c201cd1ecd17610 100644 (file)
@@ -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);