diff options
| author | j-p <jp.bruyere@live.be> | 2017-08-28 05:12:19 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-08-28 05:12:19 +0200 |
| commit | 1d9aa6aa61da3dd5f1a1a488018ceb8b5a88f2af (patch) | |
| tree | e7e9aed2ad7b0947855ce9d70a52267b128fec0c /src/GraphicObjects/GraphicObject.cs | |
| parent | d6d7eda88ae12d6c47d6c158a5a9527a47447745 (diff) | |
full IDisposable implementation (#34)
* full implementation of IDisposable, not stable, lock and still leaking
* override dispose in popper to handle _content not yet in graphic tree (when never shown), test focusedWidget when disposing
* prevent canceling thread multiple times causing a deadlock
* test parent type when trying to close window
Diffstat (limited to 'src/GraphicObjects/GraphicObject.cs')
| -rw-r--r-- | src/GraphicObjects/GraphicObject.cs | 55 |
1 files changed, 43 insertions, 12 deletions
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 8fd9a6e9..93e812de 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -41,22 +41,51 @@ namespace Crow public class GraphicObject : ILayoutable, IValueChange, IDisposable { #region IDisposable implementation + protected bool disposed = false; - public virtual void Dispose () - { - #if DEBUG_DISPOSE - Debug.WriteLine ("{0} Disposed", this.ToString()); - #endif + public void Dispose(){ + Dispose(true); + GC.SuppressFinalize(this); + } + ~GraphicObject(){ + Dispose(false); + } + protected virtual void Dispose(bool disposing){ + if (disposed){ + #if DEBUG_DISPOSE + Debug.WriteLine ("Trying to dispose already disposed obj: {0}", this.ToString()); + #endif + return; + } - parent = null; - if (IsQueueForRedraw) - Debugger.Break (); - if (!localDataSourceIsNull) - DataSource = null; + if (disposing) { + #if DEBUG_DISPOSE + Debug.WriteLine ("Disposing: {0}", this.ToString()); + if (IsQueueForRedraw) + throw new Exception("Trying to dispose an object queued for Redraw: " + this.ToString()); + #endif + if (currentInterface.HoverWidget != null) { + if (currentInterface.HoverWidget.IsOrIsInside(this)) + currentInterface.HoverWidget = null; + } + if (currentInterface.ActiveWidget != null) { + if (currentInterface.ActiveWidget.IsOrIsInside (this)) + currentInterface.ActiveWidget = null; + } + if (currentInterface.FocusedWidget != null) { + if (currentInterface.FocusedWidget.IsOrIsInside (this)) + currentInterface.FocusedWidget = null; + } + if (!localDataSourceIsNull) + DataSource = null; + parent = null; + } else + Debug.WriteLine ("!!! Finalized by GC: {0}", this.ToString ()); Clipping?.Dispose (); bmp?.Dispose (); - } + disposed = true; + } #endregion internal static ulong currentUid = 0; @@ -826,7 +855,9 @@ namespace Crow /// <summary> /// return true if this is contained inside go /// </summary> - public bool IsInside(GraphicObject go){ + public bool IsOrIsInside(GraphicObject go){ + if (this == go) + return true; ILayoutable p = this.Parent; while (p != null) { if (p == go) |