]> Pileus Git - grits/commitdiff
Better error checking for elev and sat plugins
authorAndy Spencer <andy753421@gmail.com>
Wed, 3 Feb 2010 02:13:08 +0000 (02:13 +0000)
committerAndy Spencer <andy753421@gmail.com>
Wed, 3 Feb 2010 02:13:08 +0000 (02:13 +0000)
src/plugins/elev.c
src/plugins/sat.c

index adb25ee989873a81db0e09b99b63318246549fb4..4c28847a40b2972098013e0b2018c6477df36679 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 #include <gtk/gtkgl.h>
+#include <glib/gstdio.h>
 #include <GL/gl.h>
 
 #include <gis.h>
@@ -25,6 +26,7 @@
 #define MAX_RESOLUTION 500
 #define TILE_WIDTH     1024
 #define TILE_HEIGHT    512
+#define TILE_SIZE      (TILE_WIDTH*TILE_HEIGHT*sizeof(guint16))
 
 struct _TileData {
        /* OpenGL has to be first to make gis_opengl_render_tiles happy */
@@ -99,9 +101,16 @@ struct _LoadTileData {
 };
 static guint16 *_load_bil(gchar *path)
 {
-       gchar *data;
-       g_file_get_contents(path, &data, NULL, NULL);
+       gsize len;
+       gchar *data = NULL;
+       g_file_get_contents(path, &data, &len, NULL);
        g_debug("GisPluginElev: load_bil %p", data);
+       if (len != TILE_SIZE) {
+               g_warning("GisPluginElev: _load_bil - unexpected tile size %d, != %d",
+                               len, TILE_SIZE);
+               g_free(data);
+               return NULL;
+       }
        return (guint16*)data;
 }
 static GdkPixbuf *_load_pixbuf(guint16 *bil)
@@ -191,10 +200,18 @@ static void _load_tile(GisTile *tile, gpointer _self)
        load->self = self;
        load->tile = tile;
        load->data = g_new0(struct _TileData, 1);
-       if (LOAD_BIL || LOAD_OPENGL)
+       if (LOAD_BIL || LOAD_OPENGL) {
                load->data->bil = _load_bil(load->path);
-       if (LOAD_OPENGL)
+               if (!load->data->bil) {
+                       g_remove(load->path);
+                       g_free(load->path);
+                       g_free(load);
+                       return;
+               }
+       }
+       if (LOAD_OPENGL) {
                load->pixbuf = _load_pixbuf(load->data->bil);
+       }
 
        g_idle_add_full(G_PRIORITY_LOW, _load_tile_cb, load, NULL);
 }
index 155b30c322522dbee51b465d53bc5cb1751f70f3..d65f833608fc4498285180ce84f5918ef9ebbeaf 100644 (file)
@@ -82,6 +82,7 @@ static void _load_tile(GisTile *tile, gpointer _self)
                g_idle_add_full(G_PRIORITY_LOW, _load_tile_cb, data, NULL);
        } else {
                g_warning("GisPluginSat: _load_tile - Error loading pixbuf %s", path);
+               g_free(data);
                g_remove(path);
        }
        g_free(path);