Debugging and memory checking
authorAndy Spencer <andy753421@gmail.com>
Sat, 6 Feb 2010 12:55:27 +0000 (12:55 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sat, 6 Feb 2010 12:55:27 +0000 (12:55 +0000)
src/.vimrc
src/data/gis-http.c
src/data/gis-wms.c
src/gis-opengl.c
src/gis-opengl.h
src/gis-test.c
src/objects/gis-tile.c
src/roam.c

index 5de2904..b071c55 100644 (file)
@@ -1,2 +1,4 @@
 set makeprg=make\ test
 set tw=100
+au FileType valgrind syn match gisFile "\v<(gis-\w+|elev|env|map|sat|test)\.c>" containedin=valgrindSrc
+au FileType valgrind hi link gisFile Error
index 0b29c4d..e89d252 100644 (file)
@@ -24,6 +24,7 @@
 
 GisHttp *gis_http_new(const gchar *prefix)
 {
+       g_debug("GisHttp: new - %s", prefix);
        GisHttp *self = g_new0(GisHttp, 1);
        self->soup = soup_session_sync_new();
        self->prefix = g_strdup(prefix);
@@ -33,6 +34,8 @@ GisHttp *gis_http_new(const gchar *prefix)
 
 void gis_http_free(GisHttp *self)
 {
+       g_debug("GisHttp: free - %s", self->prefix);
+       soup_session_abort(self->soup);
        g_object_unref(self->soup);
        g_free(self->prefix);
        g_free(self);
@@ -75,7 +78,8 @@ static void _chunk_cb(SoupMessage *message, SoupBuffer *chunk, gpointer _info)
 gchar *gis_http_fetch(GisHttp *self, const gchar *uri, const char *local,
                GisCacheType mode, GisChunkCallback callback, gpointer user_data)
 {
-       g_debug("GisHttp: fetch - %s >> %s  mode=%d", uri, self->prefix, mode);
+       g_debug("GisHttp: fetch - %.20s... >> %s/%s  mode=%d",
+                       uri, self->prefix, local, mode);
 
        gchar *path = g_build_filename(g_get_user_cache_dir(), PACKAGE,
                        self->prefix, local, NULL);
index 23bc3f7..509a18e 100644 (file)
@@ -109,6 +109,7 @@ GisWms *gis_wms_new(
        const gchar *uri_format, const gchar *prefix,
        const gchar *extension, gint width, gint height)
 {
+       g_debug("GisWms: new - %s", uri_prefix);
        GisWms *self = g_new0(GisWms, 1);
        self->http         = gis_http_new(prefix);
        self->uri_prefix   = g_strdup(uri_prefix);
@@ -122,6 +123,7 @@ GisWms *gis_wms_new(
 
 void gis_wms_free(GisWms *self)
 {
+       g_debug("GisWms: free - %s", self->uri_prefix);
        gis_http_free(self->http);
        g_free(self->uri_prefix);
        g_free(self->uri_layer);
index 420e213..d85b70b 100644 (file)
@@ -296,7 +296,6 @@ static void _unload_object(GisOpenGL *self, GisObject *object)
        g_debug("GisOpenGL: unload_object");
        if (GIS_IS_MARKER(object)) {
                GisMarker *marker = GIS_MARKER(object);
-               g_debug("delete_texture: %d", marker->tex);
                glDeleteTextures(1, &marker->tex);
        }
 }
@@ -444,7 +443,8 @@ static void on_view_changed(GisOpenGL *self,
        gdk_threads_enter();
        _set_visuals(self);
 #ifndef ROAM_DEBUG
-       g_idle_add_full(G_PRIORITY_HIGH_IDLE+30, _update_errors_cb, self->sphere, NULL);
+       self->ue_source = g_idle_add_full(G_PRIORITY_HIGH_IDLE+30,
+                       _update_errors_cb, self->sphere, NULL);
        //roam_sphere_update_errors(self->sphere);
 #endif
        gdk_threads_leave();
@@ -651,6 +651,10 @@ static void gis_opengl_dispose(GObject *_self)
                g_source_remove(self->sm_source[1]);
                self->sm_source[1] = 0;
        }
+       if (self->ue_source) {
+               g_source_remove(self->ue_source);
+               self->ue_source = 0;
+       }
        G_OBJECT_CLASS(gis_opengl_parent_class)->dispose(_self);
 }
 static void gis_opengl_finalize(GObject *_self)
index df40002..80e866e 100644 (file)
@@ -42,6 +42,7 @@ struct _GisOpenGL {
        RoamSphere *sphere;
        GMutex     *sphere_lock;
        guint       sm_source[2];
+       guint       ue_source;
 
        /* for testing */
        gboolean    wireframe;
index 3364a68..7e973c1 100644 (file)
 
 #include "gis.h"
 
+GisPrefs   *prefs   = NULL;
+GisPlugins *plugins = NULL;
+GisViewer  *viewer  = NULL;
+
 /*************
  * Callbacks *
  *************/
-static gboolean on_delete(GtkWidget *widget, GdkEvent *event, gpointer data)
+static gboolean gis_shutdown(GtkWidget *window)
 {
+       gis_plugins_free(plugins);
+       g_object_unref(prefs);
+       gtk_widget_destroy(window);
+
+       while (gtk_events_pending())
+                 gtk_main_iteration();
+
        gtk_main_quit();
        return TRUE;
 }
+static gboolean on_delete(GtkWidget *widget, GdkEvent *event, gpointer data)
+{
+       return gis_shutdown(widget);
+}
 static gboolean on_key_press(GtkWidget *widget, GdkEventKey *event,
                gpointer window)
 {
-       if (event->keyval == GDK_q) {
-               gtk_main_quit();
-               return TRUE;
-       }
+       if (event->keyval == GDK_q)
+               return gis_shutdown(widget);
        return FALSE;
 }
 
@@ -48,25 +61,26 @@ int main(int argc, char **argv)
        gdk_threads_init();
        gtk_init(&argc, &argv);
 
-       GisPrefs   *prefs   = gis_prefs_new(NULL, NULL);
-       GisPlugins *plugins = gis_plugins_new(g_getenv("GIS_PLUGIN_PATH"), prefs);
-       GisViewer  *viewer  = gis_opengl_new(plugins, prefs);
+       prefs   = gis_prefs_new(NULL, NULL);
+       plugins = gis_plugins_new(g_getenv("GIS_PLUGIN_PATH"), prefs);
+       viewer  = gis_opengl_new(plugins, prefs);
 
        gdk_threads_enter();
-       GtkWidget  *window  = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+       GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        g_signal_connect(window, "delete-event",    G_CALLBACK(on_delete),    NULL);
        g_signal_connect(window, "key-press-event", G_CALLBACK(on_key_press), NULL);
        gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(viewer));
        gtk_widget_show_all(window);
 
-       gis_plugins_load(plugins, "test", viewer, prefs);
-       gis_plugins_load(plugins, "env",  viewer, prefs);
 
-       gtk_main();
+       /* elev env map sat test */
+       gis_plugins_load(plugins, "elev",  viewer, prefs);
+       gis_plugins_load(plugins, "env",   viewer, prefs);
+       gis_plugins_load(plugins, "map",   viewer, prefs);
+       gis_plugins_load(plugins, "sat",   viewer, prefs);
+       gis_plugins_load(plugins, "test",  viewer, prefs);
 
-       gis_plugins_free(plugins);
-       g_object_unref(prefs);
-       gtk_widget_destroy(window);
+       gtk_main();
 
        gdk_threads_leave();
        return 0;
index b2f96d3..2fe7202 100644 (file)
@@ -47,8 +47,8 @@ gchar *gis_tile_get_path(GisTile *child)
                        if (parent->children[x][y] == child)
                                parts = g_list_prepend(parts, gis_tile_path_table[x][y]);
        GString *path = g_string_new("");
-       for (; parts; parts = parts->next)
-               g_string_append(path, parts->data);
+       for (GList *cur = parts; cur; cur = cur->next)
+               g_string_append(path, cur->data);
        g_list_free(parts);
        return g_string_free(path, FALSE);
 }
index e4848fa..a3bc847 100644 (file)
@@ -101,7 +101,7 @@ void roam_point_update_projection(RoamPoint *self, RoamSphere *sphere)
        static int count   = 0;
        static int version = 0;
        if (version != sphere->view->version) {
-               g_debug("Projected %d points", count);
+               g_debug("RoamPoint: Projected %d points", count);
                count   = 0;
                version = sphere->view->version;
        }
@@ -675,6 +675,7 @@ void roam_sphere_free_tri(RoamTriangle *tri)
 }
 void roam_sphere_free(RoamSphere *self)
 {
+       g_debug("RoamSphere: free");
        /* Slow method, but it should work */
        while (self->polys > 8)
                roam_sphere_merge_one(self);