Fix a crash when running single-threaded and dragging the time slider.
[synfig.git] / synfig-studio / trunk / src / gtkmm / canvasview.cpp
index 103f2f4..b88484f 100644 (file)
@@ -6,6 +6,7 @@
 **
 **     \legal
 **     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**     Copyright (c) 2007 Chris Moore
 **
 **     This package is free software; you can redistribute it and/or
 **     modify it under the terms of the GNU General Public License as
@@ -1941,7 +1942,16 @@ CanvasView::refresh_rend_desc()
 bool
 CanvasView::close()
 {
-       get_instance()->safe_close();
+       if (get_work_area()->get_updating())
+       {
+               get_work_area()->stop_updating(true); // stop and mark as cancelled
+
+               // give the workarea chances to stop updating
+               Glib::signal_timeout().connect(sigc::mem_fun(*this, &CanvasView::close_instance_when_safe) ,250);
+               return false;
+       }
+
+       close_instance_when_safe();
        return false;
 }
 
@@ -3525,10 +3535,12 @@ static bool _close_instance(etl::handle<Instance> instance)
 }
 
 bool
-CanvasView::on_delete_event(GdkEventAny* event)
+CanvasView::close_instance_when_safe()
 {
+       if (get_work_area()->get_updating())
+               return true;
+
        if(get_instance()->get_visible_canvases()==1)
-       {
                // Schedule a close to occur in a few moments
                Glib::signal_timeout().connect(
                        sigc::bind(
@@ -3537,9 +3549,18 @@ CanvasView::on_delete_event(GdkEventAny* event)
                        )
                        ,250
                );
-       }
-       if(event)
-               return Gtk::Window::on_delete_event(event);
+
+       return false;
+}
+
+bool
+CanvasView::on_delete_event(GdkEventAny* event)
+{
+       close();
+
+       //! \todo This causes the window to be deleted straight away - but what if we prompt 'save?' and the user cancels?
+       //                Is there ever any need to pass on the delete event to the window here?
+       // if(event) return Gtk::Window::on_delete_event(event);
 
        return true;
 }