[libchamplain/libchamplain-0-12] In idle functions check whether ClutterActor was destroyed
- From: JiÅÃ Techet <jiritechet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libchamplain/libchamplain-0-12] In idle functions check whether ClutterActor was destroyed
- Date: Tue, 20 Dec 2011 01:14:33 +0000 (UTC)
commit 8ca190812387ed370f89677734b9d12e8f8d232d
Author: JiÅÃ Techet <techet gmail com>
Date: Sun Nov 20 15:06:43 2011 +0100
In idle functions check whether ClutterActor was destroyed
Clutter actor can be destroyed using clutter_actor_destroy()
which causes immediate call of dispose no matter how many
refs the given object has. In idle functions we have to check
whether this happened to current object (by checking whether
some of the referenced objects is NULL) and if so, return from
the idle function immediately.
This commit also adds one testing example which quickly creates
and destroys ChamplainView, which can easily verify the presence
of the original bug.
.gitignore | 1 +
champlain/champlain-label.c | 3 +
champlain/champlain-path-layer.c | 2 +-
champlain/champlain-scale.c | 2 +-
champlain/champlain-tile.c | 8 +++-
champlain/champlain-view.c | 3 +
demos/Makefile.am | 5 ++-
demos/create-destroy-test.c | 76 ++++++++++++++++++++++++++++++++++++++
8 files changed, 96 insertions(+), 4 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 6df358a..fd9de7e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -44,6 +44,7 @@ demos/url-marker
demos/local-rendering
demos/minimal
demos/minimal-gtk
+demos/create-destroy-test
demos/launcher-vala
demos/launcher-vala.c
demos/markers-vala.c
diff --git a/champlain/champlain-label.c b/champlain/champlain-label.c
index b291eb9..98e706d 100644
--- a/champlain/champlain-label.c
+++ b/champlain/champlain-label.c
@@ -782,6 +782,9 @@ draw_label (ChamplainLabel *label)
ChamplainMarker *marker = CHAMPLAIN_MARKER (label);
guint height = 0, point = 0;
guint total_width = 0, total_height = 0;
+
+ if (!priv->content_group)
+ return;
if (priv->image != NULL)
{
diff --git a/champlain/champlain-path-layer.c b/champlain/champlain-path-layer.c
index 64c9974..32c6976 100644
--- a/champlain/champlain-path-layer.c
+++ b/champlain/champlain-path-layer.c
@@ -675,7 +675,7 @@ redraw_path (ChamplainPathLayer *layer)
priv->redraw_scheduled = FALSE;
/* layer not yet added to the view */
- if (view == NULL)
+ if (view == NULL || !priv->content_group)
return FALSE;
clutter_actor_get_size (CLUTTER_ACTOR (view), &width, &height);
diff --git a/champlain/champlain-scale.c b/champlain/champlain-scale.c
index a4befcd..68ace95 100644
--- a/champlain/champlain-scale.c
+++ b/champlain/champlain-scale.c
@@ -330,7 +330,7 @@ redraw_scale (ChamplainScale *scale)
priv->redraw_scheduled = FALSE;
- if (!priv->view)
+ if (!priv->view || !priv->content_group)
return FALSE;
zoom_level = champlain_view_get_zoom_level (priv->view);
diff --git a/champlain/champlain-tile.c b/champlain/champlain-tile.c
index cd57612..8b2d165 100644
--- a/champlain/champlain-tile.c
+++ b/champlain/champlain-tile.c
@@ -858,6 +858,9 @@ champlain_tile_set_content (ChamplainTile *self,
ChamplainTilePrivate *priv = self->priv;
+ if (!priv->content_group)
+ return;
+
if (!priv->content_displayed && priv->content_actor)
clutter_actor_destroy (priv->content_actor);
@@ -872,6 +875,9 @@ static void
fade_in_completed (G_GNUC_UNUSED ClutterAnimation *animation, ChamplainTile *self)
{
ChamplainTilePrivate *priv = self->priv;
+
+ if (!priv->content_group)
+ return;
if (clutter_group_get_n_children (CLUTTER_GROUP (priv->content_group)) > 1)
clutter_actor_destroy (clutter_group_get_nth_child (CLUTTER_GROUP (priv->content_group), 0));
@@ -894,7 +900,7 @@ champlain_tile_display_content (ChamplainTile *self)
ChamplainTilePrivate *priv = self->priv;
ClutterAnimation *animation;
- if (!priv->content_actor || priv->content_displayed)
+ if (!priv->content_actor || priv->content_displayed || !priv->content_group)
return;
clutter_container_add_actor (CLUTTER_CONTAINER (priv->content_group), priv->content_actor);
diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c
index fa8a715..f39cf0e 100644
--- a/champlain/champlain-view.c
+++ b/champlain/champlain-view.c
@@ -589,6 +589,9 @@ _update_idle_cb (ChamplainView *view)
DEBUG_LOG ()
ChamplainViewPrivate *priv = view->priv;
+
+ if (!priv->kinetic_scroll)
+ return FALSE;
clutter_actor_set_size (priv->kinetic_scroll,
priv->viewport_width,
diff --git a/demos/Makefile.am b/demos/Makefile.am
index f790839..f64a693 100644
--- a/demos/Makefile.am
+++ b/demos/Makefile.am
@@ -1,4 +1,4 @@
-noinst_PROGRAMS = minimal launcher animated-marker polygons url-marker
+noinst_PROGRAMS = minimal launcher animated-marker polygons url-marker create-destroy-test
INCLUDES = -I$(top_srcdir)
@@ -21,6 +21,9 @@ url_marker_SOURCES = url-marker.c
url_marker_CPPFLAGS = $(DEPS_CFLAGS) $(SOUP_CFLAGS)
url_marker_LDADD = $(SOUP_LIBS) $(DEPS_LIBS) ../champlain/libchamplain- CHAMPLAIN_API_VERSION@.la
+create_destroy_test_SOURCES = create-destroy-test.c
+create_destroy_test_LDADD = $(DEPS_LIBS) ../champlain/libchamplain- CHAMPLAIN_API_VERSION@.la
+
if ENABLE_GTK
noinst_PROGRAMS += minimal-gtk
minimal_gtk_SOURCES = minimal-gtk.c
diff --git a/demos/create-destroy-test.c b/demos/create-destroy-test.c
new file mode 100644
index 0000000..efc3521
--- /dev/null
+++ b/demos/create-destroy-test.c
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2010 Jiri Techet <techet gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <champlain/champlain.h>
+
+static ClutterActor *
+create_actor ()
+{
+ ClutterActor *actor, *stage;
+
+ stage = clutter_stage_get_default ();
+
+ /* Create the map view */
+ actor = champlain_view_new ();
+ clutter_actor_set_size (CLUTTER_ACTOR (actor), 800, 600);
+ clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor);
+
+ champlain_view_set_zoom_level (CHAMPLAIN_VIEW (actor), 12);
+ champlain_view_center_on (CHAMPLAIN_VIEW (actor), 45.466, -73.75);
+
+ return actor;
+}
+
+
+static gboolean
+callback (void *data)
+{
+ static ClutterActor *actor = NULL;
+
+ if (!actor)
+ {
+ actor = create_actor();
+ }
+ else
+ {
+ clutter_actor_destroy (actor);
+ actor = NULL;
+ }
+
+ return TRUE;
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ ClutterActor *stage;
+
+ if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
+ return 1;
+
+ stage = clutter_stage_get_default ();
+ clutter_actor_set_size (stage, 800, 600);
+
+ g_timeout_add (100, (GSourceFunc) callback, NULL);
+
+ clutter_actor_show (stage);
+ clutter_main ();
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]