]> git.street.me.uk Git - andy/viking.git/blobdiff - src/mapcache.c
Merge branch 'GeoRefImprove'
[andy/viking.git] / src / mapcache.c
index 2641a9fa6799c152af6aad2f0d7d39ddaae51b69..449caf8f9566c2e8409d64003d2af3731188a3eb 100644 (file)
@@ -47,7 +47,7 @@ static GHashTable *cache = NULL;
 static GMutex *mc_mutex = NULL;
 
 #define HASHKEY_FORMAT_STRING "%d-%d-%d-%d-%d-%d-%d-%.3f-%.3f"
-#define HASHKEY_FORMAT_STRING_NOSHRINK "%d-%d-%d-%d-%d-%d-"
+#define HASHKEY_FORMAT_STRING_NOSHRINK_NOR_ALPHA "%d-%d-%d-%d-%d-%d-"
 
 static VikLayerParamScale params_scales[] = {
   /* min, max, step, digits (decimal places) */
@@ -70,7 +70,14 @@ void a_mapcache_init ()
 
 static void cache_add(gchar *key, GdkPixbuf *pixbuf)
 {
-  if ( g_hash_table_insert ( cache, key, pixbuf ) ) {
+#if !GLIB_CHECK_VERSION(2,26,0)
+  // Only later versions of GLib actually return a value for this function
+  // Annoyingly the documentation doesn't say anything about this interface change :(
+  if ( g_hash_table_insert ( cache, key, pixbuf ) )
+#else
+  g_hash_table_insert ( cache, key, pixbuf );
+#endif
+  {
     cache_size += gdk_pixbuf_get_rowstride(pixbuf) * gdk_pixbuf_get_height(pixbuf);
     cache_size += 100;
   }
@@ -175,13 +182,14 @@ void a_mapcache_remove_all_shrinkfactors ( gint x, gint y, gint z, guint16 type,
   if ( queue_tail == NULL )
     return;
 
-  g_snprintf ( key, sizeof(key), HASHKEY_FORMAT_STRING_NOSHRINK, x, y, z, type, zoom, 0 );
+  g_snprintf ( key, sizeof(key), HASHKEY_FORMAT_STRING_NOSHRINK_NOR_ALPHA, x, y, z, type, zoom, 0 );
   len = strlen(key);
 
   g_mutex_lock(mc_mutex);
   /* TODO: check logic here */
   do {
     tmp = loop->next;
+    if ( tmp ) {
     if ( strncmp(tmp->key, key, len) == 0 )
     {
       cache_remove(tmp->key);
@@ -198,7 +206,8 @@ void a_mapcache_remove_all_shrinkfactors ( gint x, gint y, gint z, guint16 type,
     }
     else
       loop = tmp;
-
+    } else
+      loop = NULL;
   } while ( loop && (loop != queue_tail || tmp == NULL) );
 
   /* loop thru list, looking for the one, compare first whatever chars */