# HG changeset patch # User John W. Eaton # Date 1318384521 14400 # Node ID de081abd32c6a9c2b216d896064f38cc8e62b50d # Parent 16a706965ee0755163c7ef9cc3ccd384080db9c3 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. diff -r 16a706965ee0 -r de081abd32c6 src/graphics.cc --- a/src/graphics.cc Tue Oct 11 18:08:44 2011 -0400 +++ b/src/graphics.cc Tue Oct 11 21:55:21 2011 -0400 @@ -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 diff -r 16a706965ee0 -r de081abd32c6 src/graphics.h.in --- a/src/graphics.h.in Tue Oct 11 18:08:44 2011 -0400 +++ b/src/graphics.h.in Tue Oct 11 21:55:21 2011 -0400 @@ -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; }; // ---------------------------------------------------------------------