- Keep references to objects in plugins and remove/free them when the
plugins are destroyed.
- g_close_dir in gis-plugin.c
#include "gis-marker.h"
/* GisMarker */
#include "gis-marker.h"
/* GisMarker */
-G_DEFINE_TYPE(GisMarker, gis_marker, GIS_TYPE_OBJECT);
-static void gis_marker_init(GisMarker *self) { }
-
-static void gis_marker_finalize(GObject *_self);
-static void gis_marker_class_init(GisMarkerClass *klass)
-{
- G_OBJECT_CLASS(klass)->finalize = gis_marker_finalize;
-}
-
GisMarker *gis_marker_new(const gchar *label)
{
GisMarker *gis_marker_new(const gchar *label)
{
+ //g_debug("GisMarker: new - %s", label);
static const int RADIUS = 4;
static const int WIDTH = 100;
static const int HEIGHT = 20;
static const int RADIUS = 4;
static const int WIDTH = 100;
static const int HEIGHT = 20;
+G_DEFINE_TYPE(GisMarker, gis_marker, GIS_TYPE_OBJECT);
+static void gis_marker_init(GisMarker *self) { }
+
static void gis_marker_finalize(GObject *_self)
{
GisMarker *self = GIS_MARKER(_self);
static void gis_marker_finalize(GObject *_self)
{
GisMarker *self = GIS_MARKER(_self);
- cairo_surface_destroy(cairo_get_target(self->cairo));
+ //g_debug("GisMarker: finalize - %s", self->label);
+ cairo_surface_t *surface = cairo_get_target(self->cairo);
+ cairo_surface_destroy(surface);
cairo_destroy(self->cairo);
g_free(self->label);
cairo_destroy(self->cairo);
g_free(self->label);
+}
+
+static void gis_marker_class_init(GisMarkerClass *klass)
+{
+ G_OBJECT_CLASS(klass)->finalize = gis_marker_finalize;
+/* Use GObject for this */
void gis_tile_free(GisTile *self, GisTileFreeFunc free_func, gpointer user_data)
{
if (!self)
void gis_tile_free(GisTile *self, GisTileFreeFunc free_func, gpointer user_data)
{
if (!self)
{
g_debug("GisPluginEnv: new");
GisPluginEnv *self = g_object_new(GIS_TYPE_PLUGIN_ENV, NULL);
{
g_debug("GisPluginEnv: new");
GisPluginEnv *self = g_object_new(GIS_TYPE_PLUGIN_ENV, NULL);
+ self->viewer = g_object_ref(viewer);
- /* Load blank background texture */
+ /* Create objects */
+ GisCallback *callback = gis_callback_new(expose, self);
+ GisTile *background = gis_tile_new(NULL, NORTH, SOUTH, EAST, WEST);
glGenTextures(1, &self->tex);
glGenTextures(1, &self->tex);
- self->background = gis_tile_new(NULL, NORTH, SOUTH, EAST, WEST);
- self->background->data = &self->tex;
+ background->data = &self->tex;
- GisCallback *callback = gis_callback_new(expose, self);
- gis_viewer_add(viewer, GIS_OBJECT(callback), GIS_LEVEL_BACKGROUND, 0);
- gis_viewer_add(viewer, GIS_OBJECT(self->background), GIS_LEVEL_BACKGROUND, 0);
+ gpointer ref1, ref2;
+ ref1 = gis_viewer_add(viewer, GIS_OBJECT(callback), GIS_LEVEL_BACKGROUND, FALSE);
+ ref2 = gis_viewer_add(viewer, GIS_OBJECT(background), GIS_LEVEL_BACKGROUND, FALSE);
+ self->refs = g_list_prepend(self->refs, ref1);
+ self->refs = g_list_prepend(self->refs, ref2);
g_debug("GisPluginEnv: dispose");
GisPluginEnv *self = GIS_PLUGIN_ENV(gobject);
/* Drop references */
g_debug("GisPluginEnv: dispose");
GisPluginEnv *self = GIS_PLUGIN_ENV(gobject);
/* Drop references */
+ if (self->viewer) {
+ for (GList *cur = self->refs; cur; cur = cur->next)
+ gis_viewer_remove(self->viewer, cur->data);
+ g_list_free(self->refs);
+ g_object_unref(self->viewer);
+ glDeleteTextures(1, &self->tex);
+ self->viewer = NULL;
+ }
G_OBJECT_CLASS(gis_plugin_env_parent_class)->dispose(gobject);
}
static void gis_plugin_env_class_init(GisPluginEnvClass *klass)
{
g_debug("GisPluginEnv: class_init");
GObjectClass *gobject_class = (GObjectClass*)klass;
G_OBJECT_CLASS(gis_plugin_env_parent_class)->dispose(gobject);
}
static void gis_plugin_env_class_init(GisPluginEnvClass *klass)
{
g_debug("GisPluginEnv: class_init");
GObjectClass *gobject_class = (GObjectClass*)klass;
- gobject_class->dispose = gis_plugin_env_dispose;
+ gobject_class->dispose = gis_plugin_env_dispose;
GisViewer *viewer;
guint tex;
GisTile *background;
GisViewer *viewer;
guint tex;
GisTile *background;
};
struct _GisPluginEnvClass {
};
struct _GisPluginEnvClass {
{
g_debug("GisPluginTest: new");
GisPluginTest *self = g_object_new(GIS_TYPE_PLUGIN_TEST, NULL);
{
g_debug("GisPluginTest: new");
GisPluginTest *self = g_object_new(GIS_TYPE_PLUGIN_TEST, NULL);
+ self->viewer = g_object_ref(viewer);
GisMarker *marker = gis_marker_new("St. Charles");
gis_point_set_lle(gis_object_center(GIS_OBJECT(marker)), 38.841847, -90.491982, 0);
GIS_OBJECT(marker)->lod = EARTH_R/4;
GisMarker *marker = gis_marker_new("St. Charles");
gis_point_set_lle(gis_object_center(GIS_OBJECT(marker)), 38.841847, -90.491982, 0);
GIS_OBJECT(marker)->lod = EARTH_R/4;
- gis_viewer_add(self->viewer, GIS_OBJECT(marker), GIS_LEVEL_OVERLAY, 0);
+ self->marker = gis_viewer_add(self->viewer, GIS_OBJECT(marker), GIS_LEVEL_OVERLAY, 0);
{
g_debug("GisPluginTest: init");
}
{
g_debug("GisPluginTest: init");
}
+static void gis_plugin_test_dispose(GObject *_self)
+{
+ g_debug("GisPluginTest: dispose");
+ GisPluginTest *self = GIS_PLUGIN_TEST(_self);
+ if (self->viewer) {
+ gis_viewer_remove(self->viewer, self->marker);
+ g_object_unref(self->viewer);
+ self->viewer = NULL;
+ }
+ G_OBJECT_CLASS(gis_plugin_test_parent_class)->finalize(_self);
+}
static void gis_plugin_test_class_init(GisPluginTestClass *klass)
{
g_debug("GisPluginTest: class_init");
static void gis_plugin_test_class_init(GisPluginTestClass *klass)
{
g_debug("GisPluginTest: class_init");
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+ gobject_class->dispose = gis_plugin_test_dispose;
/* instance members */
GisViewer *viewer;
/* instance members */
GisViewer *viewer;
};
struct _GisPluginTestClass {
};
struct _GisPluginTestClass {