[chronojump] Fixed random crash on cancelling contact tests



commit 968ffc2c40b0d3acb12cb4d3a23f33ae615b7c57
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon May 19 13:14:22 2014 +0200

    Fixed random crash on cancelling contact tests

 src/execute/event.cs          |   11 +++++++-
 src/execute/jump.cs           |    4 ++-
 src/execute/multiChronopic.cs |    3 +-
 src/execute/pulse.cs          |    3 +-
 src/execute/reactionTime.cs   |    3 +-
 src/execute/run.cs            |    4 ++-
 src/gui/chronojump.cs         |   57 ++++++++++++++++------------------------
 7 files changed, 45 insertions(+), 40 deletions(-)
---
diff --git a/src/execute/event.cs b/src/execute/event.cs
index caed320..e96855c 100644
--- a/src/execute/event.cs
+++ b/src/execute/event.cs
@@ -15,7 +15,7 @@
  *  along with this program; if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * Copyright (C) 2004-2012   Xavier de Blas <xaviblas gmail com> 
+ * Copyright (C) 2004-2014   Xavier de Blas <xaviblas gmail com> 
  */
 
 using System;
@@ -118,6 +118,10 @@ public class EventExecute
        protected Gtk.Button fakeButtonUpdateGraph;
        protected Gtk.Button fakeButtonFinished;
        protected Gtk.Button fakeButtonEventEnded;
+       //this should be a safer way, because will be called when thread has dyed, then will be the last 
action in the GTK thread.
+       //suitable for calling sensitiveGuiEventDone without problems
+       //sensitiveGuiEventDone causes problems on changing (or even reading) properties of gtk stuff outside 
of gtk thread
+       protected Gtk.Button fakeButtonThreadDyed;
        
        //for cancelling from chronojump.cs
        protected bool cancel;
@@ -229,6 +233,7 @@ public class EventExecute
                //then thread is dead
 
                if ( ! thread.IsAlive || cancel) {
+                       fakeButtonThreadDyed.Click();
                        Log.Write("dying");
 
                        return false;
@@ -513,6 +518,10 @@ public class EventExecute
        public Gtk.Button FakeButtonEventEnded {
                get { return fakeButtonEventEnded; }
        }
+       
+       public Gtk.Button FakeButtonThreadDyed {
+               get { return fakeButtonThreadDyed; }
+       }
 
        //public Gtk.Button FakeButtonRunATouchPlatform {
        //      get { return fakeButtonRunATouchPlatform; }
diff --git a/src/execute/jump.cs b/src/execute/jump.cs
index e3be9f0..5cdfa03 100644
--- a/src/execute/jump.cs
+++ b/src/execute/jump.cs
@@ -15,7 +15,7 @@
  *  along with this program; if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * Copyright (C) 2004-2011   Xavier de Blas <xaviblas gmail com> 
+ * Copyright (C) 2004-2014   Xavier de Blas <xaviblas gmail com> 
  */
 
 using System;
@@ -79,6 +79,7 @@ public class JumpExecute : EventExecute
                fakeButtonUpdateGraph = new Gtk.Button();
                fakeButtonEventEnded = new Gtk.Button();
                fakeButtonFinished = new Gtk.Button();
+               fakeButtonThreadDyed = new Gtk.Button();
                
                simulated = false;
                        
@@ -506,6 +507,7 @@ public class JumpRjExecute : JumpExecute
                fakeButtonUpdateGraph = new Gtk.Button();
                fakeButtonEventEnded = new Gtk.Button();
                fakeButtonFinished = new Gtk.Button();
+               fakeButtonThreadDyed = new Gtk.Button();
                
                simulated = false;
                        
diff --git a/src/execute/multiChronopic.cs b/src/execute/multiChronopic.cs
index b6d1348..cb6149c 100644
--- a/src/execute/multiChronopic.cs
+++ b/src/execute/multiChronopic.cs
@@ -15,7 +15,7 @@
  *  along with this program; if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * Copyright (C) 2004-2011   Xavier de Blas <xaviblas gmail com> 
+ * Copyright (C) 2004-2014   Xavier de Blas <xaviblas gmail com> 
  */
 
 using System;
@@ -182,6 +182,7 @@ public class MultiChronopicExecute : EventExecute
                fakeButtonUpdateGraph = new Gtk.Button();
                fakeButtonEventEnded = new Gtk.Button();
                fakeButtonFinished = new Gtk.Button();
+               fakeButtonThreadDyed = new Gtk.Button();
                simulated = false;
 
                cp1InStr = "";
diff --git a/src/execute/pulse.cs b/src/execute/pulse.cs
index 5d57f6d..7e4ca43 100644
--- a/src/execute/pulse.cs
+++ b/src/execute/pulse.cs
@@ -15,7 +15,7 @@
  *  along with this program; if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * Copyright (C) 2004-2011   Xavier de Blas <xaviblas gmail com> 
+ * Copyright (C) 2004-2014   Xavier de Blas <xaviblas gmail com> 
  */
 
 using System;
@@ -79,6 +79,7 @@ public class PulseExecute : EventExecute
                fakeButtonUpdateGraph = new Gtk.Button();
                fakeButtonEventEnded = new Gtk.Button();
                fakeButtonFinished = new Gtk.Button();
+               fakeButtonThreadDyed = new Gtk.Button();
 
                simulated = false;
                
diff --git a/src/execute/reactionTime.cs b/src/execute/reactionTime.cs
index 2503a07..a12c635 100644
--- a/src/execute/reactionTime.cs
+++ b/src/execute/reactionTime.cs
@@ -15,7 +15,7 @@
  *  along with this program; if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * Copyright (C) 2004-2011   Xavier de Blas <xaviblas gmail com> 
+ * Copyright (C) 2004-2014   Xavier de Blas <xaviblas gmail com> 
  */
 
 using System;
@@ -61,6 +61,7 @@ public class ReactionTimeExecute : EventExecute
                fakeButtonUpdateGraph = new Gtk.Button();
                fakeButtonEventEnded = new Gtk.Button();
                fakeButtonFinished = new Gtk.Button();
+               fakeButtonThreadDyed = new Gtk.Button();
                
                simulated = false;
                        
diff --git a/src/execute/run.cs b/src/execute/run.cs
index 4b7e282..1f1cd4d 100644
--- a/src/execute/run.cs
+++ b/src/execute/run.cs
@@ -15,7 +15,7 @@
  *  along with this program; if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * Copyright (C) 2004-2012   Xavier de Blas <xaviblas gmail com> 
+ * Copyright (C) 2004-2014   Xavier de Blas <xaviblas gmail com> 
  */
 
 using System;
@@ -84,6 +84,7 @@ public class RunExecute : EventExecute
                fakeButtonUpdateGraph = new Gtk.Button();
                fakeButtonEventEnded = new Gtk.Button();
                fakeButtonFinished = new Gtk.Button();
+               fakeButtonThreadDyed = new Gtk.Button();
 
                simulated = false;
                
@@ -518,6 +519,7 @@ public class RunIntervalExecute : RunExecute
                fakeButtonUpdateGraph = new Gtk.Button();
                fakeButtonEventEnded = new Gtk.Button();
                fakeButtonFinished = new Gtk.Button();
+               fakeButtonThreadDyed = new Gtk.Button();
 
                simulated = false;
                
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index e8c524f..e352478 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -3169,14 +3169,13 @@ public partial class ChronoJumpWindow
 
        private void on_cancel_clicked (object o, EventArgs args) 
        {
+               event_execute_ButtonCancel.Clicked -= new EventHandler(on_cancel_clicked);
+
                Console.WriteLine("cancel clicked one");
 
                //this will cancel jumps or runs
                currentEventExecute.Cancel = true;
 
-               //unhide event buttons for next event
-               sensitiveGuiEventDone();
-
                if(chronopicWin.Connected)
                        checkCancelTotally(o, args);
 
@@ -3198,9 +3197,6 @@ public partial class ChronoJumpWindow
                //this will cancel jumps or runs
                currentEventExecute.Cancel = true;
 
-               //unhide event buttons for next event
-               sensitiveGuiEventDone();
-
                if(chronopicWin.Connected)
                        checkCancelMultiTotally(o, args);
        }
@@ -3268,7 +3264,9 @@ public partial class ChronoJumpWindow
                currentEventExecute.Finish = true;
                
                //unhide event buttons for next event
+Log.WriteLine("calling sensitiveGuiEventDone from on_finish_clicked");
                sensitiveGuiEventDone();
+Log.WriteLine("called sensitiveGuiEventDone from on_finish_clicked");
 
                if(chronopicWin.Connected)
                        checkFinishTotally(o, args);
@@ -3291,10 +3289,6 @@ public partial class ChronoJumpWindow
 
                currentEventExecute.Finish = true;
                
-               //unhide event buttons for next event
-               Console.WriteLine("RR0");
-               sensitiveGuiEventDone();
-
                //runA is not called for this, because it ends different
                //and there's a message on gui/eventExecute.cs for runA 
                Console.WriteLine("RR1");
@@ -3602,6 +3596,7 @@ Console.WriteLine("X");
                currentEventExecute.FakeButtonEventEnded.Clicked += new 
EventHandler(on_event_execute_EventEnded);
 
                currentEventExecute.FakeButtonFinished.Clicked += new EventHandler(on_jump_finished);
+               currentEventExecute.FakeButtonThreadDyed.Clicked += new 
EventHandler(on_test_finished_can_touch_gtk);
        }       
        
 
@@ -3670,10 +3665,17 @@ Log.WriteLine("DDD 1");
                        execute_auto_order_pos ++;
                        execute_auto_select();
                        sensitiveGuiAutoExecuteOrWait (false);
-               } else
-                       sensitiveGuiEventDone();
+               }
 Log.WriteLine("DDD 2");
        }
+               
+       private void on_test_finished_can_touch_gtk (object o, EventArgs args)
+       {
+               currentEventExecute.FakeButtonThreadDyed.Clicked -= new 
EventHandler(on_test_finished_can_touch_gtk);
+               Log.WriteLine(" cantouch1 ");
+               sensitiveGuiEventDone();
+               Log.WriteLine(" cantouch3 ");
+       }
 
 
 
@@ -3764,6 +3766,7 @@ Log.WriteLine("DDD 2");
                        new EventHandler(on_event_execute_update_graph_in_progress_clicked);
                currentEventExecute.FakeButtonEventEnded.Clicked += new 
EventHandler(on_event_execute_EventEnded);
                currentEventExecute.FakeButtonFinished.Clicked += new EventHandler(on_jump_rj_finished);
+               currentEventExecute.FakeButtonThreadDyed.Clicked += new 
EventHandler(on_test_finished_can_touch_gtk);
        }
                
        private void on_jump_rj_finished (object o, EventArgs args) 
@@ -3829,10 +3832,6 @@ Log.WriteLine("DDD 2");
                
                //delete the temp tables if exists
                Sqlite.DeleteTempEvents("tempJumpRj");
-
-
-               //unhide buttons that allow jumping
-               sensitiveGuiEventDone();
        }
 
        /* ---------------------------------------------------------
@@ -3926,6 +3925,7 @@ Log.WriteLine("DDD 2");
                        new EventHandler(on_event_execute_update_graph_in_progress_clicked);
                currentEventExecute.FakeButtonEventEnded.Clicked += new 
EventHandler(on_event_execute_EventEnded);
                currentEventExecute.FakeButtonFinished.Clicked += new EventHandler(on_run_finished);
+               currentEventExecute.FakeButtonThreadDyed.Clicked += new 
EventHandler(on_test_finished_can_touch_gtk);
        }
        
        private void on_run_finished (object o, EventArgs args)
@@ -3966,9 +3966,6 @@ Log.WriteLine("DDD 2");
                }
                
                lastRunIsSimple = true;
-               
-               //unhide buttons that allow jumping, running
-               sensitiveGuiEventDone();
        }
 
        /* ---------------------------------------------------------
@@ -4056,6 +4053,7 @@ Log.WriteLine("DDD 2");
                        new EventHandler(on_event_execute_update_graph_in_progress_clicked);
                currentEventExecute.FakeButtonEventEnded.Clicked += new 
EventHandler(on_event_execute_EventEnded);
                currentEventExecute.FakeButtonFinished.Clicked += new EventHandler(on_run_interval_finished);
+               currentEventExecute.FakeButtonThreadDyed.Clicked += new 
EventHandler(on_test_finished_can_touch_gtk);
        }
 
 
@@ -4112,10 +4110,6 @@ Log.WriteLine("DDD 2");
                
                //delete the temp tables if exists
                Sqlite.DeleteTempEvents("tempRunInterval");
-
-               
-               //unhide buttons that allow jumping, running
-               sensitiveGuiEventDone();
        }
 
        /* ---------------------------------------------------------
@@ -4172,6 +4166,7 @@ Log.WriteLine("DDD 2");
                        new EventHandler(on_event_execute_update_graph_in_progress_clicked);
                currentEventExecute.FakeButtonEventEnded.Clicked += new 
EventHandler(on_event_execute_EventEnded);
                currentEventExecute.FakeButtonFinished.Clicked += new EventHandler(on_reaction_time_finished);
+               currentEventExecute.FakeButtonThreadDyed.Clicked += new 
EventHandler(on_test_finished_can_touch_gtk);
        }       
 
 
@@ -4208,9 +4203,6 @@ Log.WriteLine("DDD 2");
                        Log.WriteLine("DISCONNECTED gui/cj");
                        createChronopicWindow(true);
                }
-               
-               //unhide buttons that allow jumping
-               sensitiveGuiEventDone();
        }
 
 
@@ -4283,6 +4275,7 @@ Log.WriteLine("DDD 2");
                        new EventHandler(on_event_execute_update_graph_in_progress_clicked);
                currentEventExecute.FakeButtonEventEnded.Clicked += new 
EventHandler(on_event_execute_EventEnded);
                currentEventExecute.FakeButtonFinished.Clicked += new EventHandler(on_pulse_finished);
+               currentEventExecute.FakeButtonThreadDyed.Clicked += new 
EventHandler(on_test_finished_can_touch_gtk);
        }
 
        private void on_pulse_finished (object o, EventArgs args) 
@@ -4335,9 +4328,6 @@ Log.WriteLine("DDD 2");
                        Log.WriteLine("DISCONNECTED gui/cj");
                        createChronopicWindow(true);
                }
-               
-               //unhide buttons that allow jumping, running
-               sensitiveGuiEventDone();
        }
 
        /* ---------------------------------------------------------
@@ -4539,6 +4529,7 @@ Log.WriteLine("DDD 2");
                currentEventExecute.FakeButtonEventEnded.Clicked += new 
EventHandler(on_event_execute_EventEnded);
 //             currentEventExecute.FakeButtonRunATouchPlatform.Clicked += new 
EventHandler(on_event_execute_RunATouchPlatform);
                currentEventExecute.FakeButtonFinished.Clicked += new 
EventHandler(on_multi_chronopic_finished);
+               currentEventExecute.FakeButtonThreadDyed.Clicked += new 
EventHandler(on_test_finished_can_touch_gtk);
        }
 
        bool multiFinishing;
@@ -4604,11 +4595,6 @@ Console.WriteLine("X");
                        Log.WriteLine("DISCONNECTED gui/cj");
                        createChronopicWindow(true);
                }
-               
-               //unhide buttons that allow doing another test
-               Console.WriteLine("RR3");
-               sensitiveGuiEventDone();
-               Console.WriteLine("RR4");
        }
                
 
@@ -5996,6 +5982,8 @@ Console.WriteLine("X");
        }
    
        private void sensitiveGuiEventDone () {
+               Log.Write(" sensitiveGuiEventDone start ");
+
                session_menuitem.Sensitive = true;
                help_menuitem.Sensitive = true;
                viewport_mode_small.Sensitive = true;
@@ -6038,6 +6026,7 @@ Console.WriteLine("X");
                                        break;
                        }
                }
+               Log.Write(" sensitiveGuiEventDone end ");
        }
        
        /*


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]