[longomatch] Fix exception after disposing canvas objects



commit a9a748bcc06ff799769e5b211276922999925d21
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Mon Aug 25 20:56:33 2014 +0200

    Fix exception after disposing canvas objects
    
    The singal handlers are not removed and triggered
    after the object is disposed accessing to null Objects

 LongoMatch.Drawing.Cairo/WidgetWrapper.cs |   21 +++++++++++++++++++++
 LongoMatch.Drawing/Canvas.cs              |    7 +++++++
 2 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git a/LongoMatch.Drawing.Cairo/WidgetWrapper.cs b/LongoMatch.Drawing.Cairo/WidgetWrapper.cs
index 5a9132c..6b0838f 100644
--- a/LongoMatch.Drawing.Cairo/WidgetWrapper.cs
+++ b/LongoMatch.Drawing.Cairo/WidgetWrapper.cs
@@ -55,6 +55,27 @@ namespace LongoMatch.Drawing.Cairo
                        widget.ButtonReleaseEvent += HandleButtonReleaseEvent;
                        widget.MotionNotifyEvent += HandleMotionNotifyEvent;
                }
+               
+               public void Dispose ()
+               {
+                       Dispose (true);
+                       System.GC.SuppressFinalize (this);
+               }
+
+               protected virtual void Dispose (bool disposing)
+               {
+                       if (disposing) {
+                               if (moveTimerID != 0) {
+                                       GLib.Source.Remove (moveTimerID);
+                                       moveTimerID = 0;
+                               }
+                               if (hoverTimerID != 0) {
+                                       GLib.Source.Remove (hoverTimerID);
+                                       
+                                       hoverTimerID = 0;
+                               }
+                       }
+               }
 
                public uint MoveWaitMS {
                        get;
diff --git a/LongoMatch.Drawing/Canvas.cs b/LongoMatch.Drawing/Canvas.cs
index cc75c07..02f3773 100644
--- a/LongoMatch.Drawing/Canvas.cs
+++ b/LongoMatch.Drawing/Canvas.cs
@@ -138,6 +138,13 @@ namespace LongoMatch.Drawing
                        widget.ShowTooltipEvent += HandleShowTooltipEvent;
                }
 
+               protected override void Dispose (bool disposing)
+               {
+                       if (disposing)
+                               widget.Dispose ();
+                       base.Dispose (disposing);
+               }
+
                public int ClickRepeatMS {
                        get;
                        set;


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