changeset 13323:de081abd32c6

don't execute graphics handle callback functions recursively * graphics.h.in (callback_property::executing): New data member. (callback_property::callback_property): Initialize it. graphics.cc (callback_property::execute): Protect executing member variable. Avoid executing callback if we are already doing so.
author John W. Eaton <jwe@octave.org>
date Tue, 11 Oct 2011 21:55:21 -0400
parents 16a706965ee0
children 1e12601d2697
files src/graphics.cc src/graphics.h.in
diffstat 2 files changed, 19 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/graphics.cc
+++ b/src/graphics.cc
@@ -1390,8 +1390,20 @@
 void
 callback_property::execute (const octave_value& data) const
 {
-  if (callback.is_defined () && ! callback.is_empty ())
-    gh_manager::execute_callback (get_parent (), callback, data);
+  unwind_protect frame;
+
+  // We are executing the callback function associated with this
+  // callback property.  When set to true, we avoid recursive calls to
+  // callback routines.
+  frame.protect_var (executing);
+
+  if (! executing)
+    {
+      executing = true;
+
+      if (callback.is_defined () && ! callback.is_empty ())
+        gh_manager::execute_callback (get_parent (), callback, data);
+    }
 }
 
 // Used to cache dummy graphics objects from which dynamic
--- a/src/graphics.h.in
+++ b/src/graphics.h.in
@@ -1813,10 +1813,10 @@
 public:
   callback_property (const std::string& nm, const graphics_handle& h,
                      const octave_value& m)
-    : base_property (nm, h), callback (m) { }
+    : base_property (nm, h), callback (m), executing (false) { }
 
   callback_property (const callback_property& p)
-    : base_property (p), callback (p.callback) { }
+    : base_property (p), callback (p.callback), executing (false) { }
 
   octave_value get (void) const { return callback; }
 
@@ -1854,6 +1854,9 @@
 
 private:
   octave_value callback;
+
+  // If TRUE, we are executing this callback.
+  mutable bool executing;
 };
 
 // ---------------------------------------------------------------------