From: Jean-Philippe Bruyère Date: Wed, 16 Jun 2021 14:00:50 +0000 (+0200) Subject: using try/finally to ensure mutexes release X-Git-Tag: v0.9.5-beta~15 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=5115f379fc240b1250220910b14d69bb27a32c1e;p=jp%2Fcrow.git using try/finally to ensure mutexes release --- diff --git a/Crow/src/DebugUtils/DebugLogger.cs b/Crow/src/DebugUtils/DebugLogger.cs index 2a9b75bb..e048008f 100644 --- a/Crow/src/DebugUtils/DebugLogger.cs +++ b/Crow/src/DebugUtils/DebugLogger.cs @@ -25,7 +25,7 @@ namespace Crow static bool logevt (DbgEvtType evtType) //=> IncludeEvents != DbgEvtType.None && (evtType & DiscardEvents) == 0 && (evtType & IncludeEvents) == IncludeEvents; //=> IncludeEvents != DbgEvtType.None && (evtType & DiscardEvents) == 0 && (evtType & IncludeEvents) == IncludeEvents; - => IncludeEvents == DbgEvtType.All || (IncludeEvents != DbgEvtType.None && (evtType & IncludeEvents) == IncludeEvents); + => IncludeEvents == DbgEvtType.All || (IncludeEvents != DbgEvtType.None && (evtType & IncludeEvents) != 0); diff --git a/Crow/src/Interface.cs b/Crow/src/Interface.cs index d39121b0..8755d817 100644 --- a/Crow/src/Interface.cs +++ b/Crow/src/Interface.cs @@ -924,20 +924,23 @@ namespace Crow DbgLogger.StartEvent (DbgEvtType.Update); PerformanceMeasure.Begin (PerformanceMeasure.Kind.Update); - processLayouting (); + try { + processLayouting (); - clippingRegistration (); + clippingRegistration (); - if (ctx == null) { - using (ctx = new Context (surf)) + if (ctx == null) { + using (ctx = new Context (surf)) + processDrawing (ctx); + }else processDrawing (ctx); - }else - processDrawing (ctx); + } finally { - PerformanceMeasure.End (PerformanceMeasure.Kind.Update); - DbgLogger.EndEvent (DbgEvtType.Update, true); + PerformanceMeasure.End (PerformanceMeasure.Kind.Update); + DbgLogger.EndEvent (DbgEvtType.Update, true); - Monitor.Exit (UpdateMutex); + Monitor.Exit (UpdateMutex); + } PerformanceMeasure.Notify (); } @@ -950,23 +953,23 @@ namespace Crow Monitor.Exit (LayoutMutex); return; } + DbgLogger.StartEvent (DbgEvtType.ProcessLayouting); PerformanceMeasure.Begin (PerformanceMeasure.Kind.Layouting); + try { + DiscardQueue = new Queue (LayoutingQueue.Count); + while (LayoutingQueue.Count > 0) { + LayoutingQueueItem lqi = LayoutingQueue.Dequeue (); + lqi.ProcessLayouting (); + } + LayoutingQueue = DiscardQueue; + } finally { + PerformanceMeasure.End (PerformanceMeasure.Kind.Layouting); + DbgLogger.EndEvent (DbgEvtType.ProcessLayouting, true); - DiscardQueue = new Queue (LayoutingQueue.Count); - //Debug.WriteLine ("======= Layouting queue start ======="); - - while (LayoutingQueue.Count > 0) { - LayoutingQueueItem lqi = LayoutingQueue.Dequeue (); - lqi.ProcessLayouting (); + Monitor.Exit (LayoutMutex); + DiscardQueue = null; } - LayoutingQueue = DiscardQueue; - - PerformanceMeasure.End (PerformanceMeasure.Kind.Layouting); - DbgLogger.EndEvent (DbgEvtType.ProcessLayouting, true); - - Monitor.Exit (LayoutMutex); - DiscardQueue = null; } } /// Degueue Widget to clip from DrawingQueue and register the last painted slot and the new one @@ -1005,7 +1008,6 @@ namespace Crow ctx.PushGroup (); - for (int i = GraphicTree.Count -1; i >= 0 ; i--){ Widget p = GraphicTree[i]; if (!p.IsVisible) diff --git a/Crow/src/LayoutingQueueItem.cs b/Crow/src/LayoutingQueueItem.cs index c6aa6dc6..3cfdaa47 100644 --- a/Crow/src/LayoutingQueueItem.cs +++ b/Crow/src/LayoutingQueueItem.cs @@ -82,55 +82,54 @@ namespace Crow public void ProcessLayouting() { Widget go = Layoutable as Widget; -// if (go == null) { -// Debug.WriteLine ("ERROR: processLayouting on something else than a graphic object: " + this.ToString ()); -// return; -// } + DbgLogger.StartEvent (DbgEvtType.GOProcessLayouting, this); go.parentRWLock.EnterReadLock (); - if (go.Parent == null) {//TODO:improve this - //cancel layouting for object without parent, maybe some were in queue when - //removed from a listbox - DbgLogger.AddEvent (DbgEvtType.GOProcessLayoutingWithNoParent, this); - go.parentRWLock.ExitReadLock (); - return; - } + try { + + if (go.Parent == null) {//TODO:improve this + //cancel layouting for object without parent, maybe some were in queue when + //removed from a listbox + DbgLogger.AddEvent (DbgEvtType.GOProcessLayoutingWithNoParent, this); + return; + } #if DEBUG_LOG - DbgLogger.StartEvent (DbgEvtType.GOProcessLayouting, this); - Slot = graphicObject.Slot; + Slot = graphicObject.Slot; #endif - LayoutingTries++; - if (!Layoutable.UpdateLayout (LayoutType)) { - if (LayoutingTries < Interface.MaxLayoutingTries) { - Layoutable.RegisteredLayoutings |= LayoutType; - (Layoutable as Widget).IFace.LayoutingQueue.Enqueue (this); + LayoutingTries++; + if (!Layoutable.UpdateLayout (LayoutType)) { + if (LayoutingTries < Interface.MaxLayoutingTries) { + Layoutable.RegisteredLayoutings |= LayoutType; + (Layoutable as Widget).IFace.LayoutingQueue.Enqueue (this); #if DEBUG_LOG - result = Result.Requeued; + result = Result.Requeued; #endif - } else if (DiscardCount < Interface.MaxDiscardCount) { + } else if (DiscardCount < Interface.MaxDiscardCount) { #if DEBUG_LOG - result = Result.Discarded; + result = Result.Discarded; +#endif + LayoutingTries = 0; + DiscardCount++; + Layoutable.RegisteredLayoutings |= LayoutType; + (Layoutable as Widget).IFace.DiscardQueue.Enqueue (this); + } +#if DEBUG_LOG + else { + result = Result.Deleted; + } #endif - LayoutingTries = 0; - DiscardCount++; - Layoutable.RegisteredLayoutings |= LayoutType; - (Layoutable as Widget).IFace.DiscardQueue.Enqueue (this); } #if DEBUG_LOG - else { - result = Result.Deleted; + else{ + result = Result.Success; } + NewSlot = graphicObject.Slot; #endif + }finally { + go.parentRWLock.ExitReadLock (); + DbgLogger.EndEvent (DbgEvtType.GOProcessLayouting, this); } -#if DEBUG_LOG - else{ - result = Result.Success; - } - NewSlot = graphicObject.Slot; - DbgLogger.EndEvent (DbgEvtType.GOProcessLayouting, this); -#endif - go.parentRWLock.ExitReadLock (); } public static implicit operator Widget(LayoutingQueueItem queueItem) => queueItem.Layoutable as Widget; diff --git a/Crow/src/Widgets/DockStack.cs b/Crow/src/Widgets/DockStack.cs index d72270c7..41c7f8b4 100644 --- a/Crow/src/Widgets/DockStack.cs +++ b/Crow/src/Widgets/DockStack.cs @@ -79,15 +79,18 @@ namespace Crow Rectangle cb = ClientRectangle; childrenRWLock.EnterReadLock (); - foreach (Widget c in Children) { - Rectangle bounds = c.Slot + cb.Position; - if (!bounds.ContainsOrIsEqual (lm)) - continue; - rIn = bounds; - focusedChild = c; - break; + try { + foreach (Widget c in Children) { + Rectangle bounds = c.Slot + cb.Position; + if (!bounds.ContainsOrIsEqual (lm)) + continue; + rIn = bounds; + focusedChild = c; + break; + } + } finally { + childrenRWLock.ExitReadLock (); } - childrenRWLock.ExitReadLock (); } public void onDragMouseMove (object sender, MouseMoveEventArgs e) diff --git a/Crow/src/Widgets/Group.cs b/Crow/src/Widgets/Group.cs index 9e78f187..a2a58b7f 100644 --- a/Crow/src/Widgets/Group.cs +++ b/Crow/src/Widgets/Group.cs @@ -35,12 +35,13 @@ namespace Crow } childrenRWLock.EnterWriteLock (); - - Children.Remove(child); - child.Parent = null; - child.LogicalParent = null; - - childrenRWLock.ExitWriteLock (); + try { + Children.Remove(child); + child.Parent = null; + child.LogicalParent = null; + } finally { + childrenRWLock.ExitWriteLock (); + } if (child == largestChild && Width == Measure.Fit) searchLargestChild (); @@ -56,14 +57,15 @@ namespace Crow return; } childrenRWLock.EnterWriteLock (); - - g.Parent = this; - Children.Insert (idx, g); - - childrenRWLock.ExitWriteLock (); + try { + g.Parent = this; + Children.Insert (idx, g); + } finally { + childrenRWLock.ExitWriteLock (); + } //largestChild = tallestChild = null; - if (g.LastSlots.Width > contentSize.Width) { + if (g.LastSlots.Width > contentSize.Width) {//TODO:Layout mutex? largestChild = g; contentSize.Width = g.LastSlots.Width; } @@ -79,16 +81,17 @@ namespace Crow public override void ClearChildren() { childrenRWLock.EnterWriteLock (); - - while (Children.Count > 0) { - Widget g = Children [Children.Count - 1]; - g.LayoutChanged -= OnChildLayoutChanges; - Children.RemoveAt (Children.Count - 1); - g.Dispose (); + try { + while (Children.Count > 0) { + Widget g = Children [Children.Count - 1]; + g.LayoutChanged -= OnChildLayoutChanges; + Children.RemoveAt (Children.Count - 1); + g.Dispose (); + } + } finally { + childrenRWLock.ExitWriteLock (); } - childrenRWLock.ExitWriteLock (); - resetChildrenMaxSize (); RegisterForLayouting (LayoutingType.Sizing); @@ -117,30 +120,33 @@ namespace Crow base.OnLayoutChanges (layoutType); childrenRWLock.EnterReadLock (); - //position smaller objects in group when group size is fit - switch (layoutType) { - case LayoutingType.Width: - //childrenRWLock.EnterReadLock (); - foreach (Widget c in Children) { - if (c.Width.IsRelativeToParent) - c.RegisterForLayouting (LayoutingType.Width); - else - c.RegisterForLayouting (LayoutingType.X); + try { + //position smaller objects in group when group size is fit + switch (layoutType) { + case LayoutingType.Width: + //childrenRWLock.EnterReadLock (); + foreach (Widget c in Children) { + if (c.Width.IsRelativeToParent) + c.RegisterForLayouting (LayoutingType.Width); + else + c.RegisterForLayouting (LayoutingType.X); + } + //childrenRWLock.ExitReadLock (); + break; + case LayoutingType.Height: + //childrenRWLock.EnterReadLock (); + foreach (Widget c in Children) { + if (c.Height.IsRelativeToParent) + c.RegisterForLayouting (LayoutingType.Height); + else + c.RegisterForLayouting (LayoutingType.Y); + } + //childrenRWLock.ExitReadLock (); + break; } - //childrenRWLock.ExitReadLock (); - break; - case LayoutingType.Height: - //childrenRWLock.EnterReadLock (); - foreach (Widget c in Children) { - if (c.Height.IsRelativeToParent) - c.RegisterForLayouting (LayoutingType.Height); - else - c.RegisterForLayouting (LayoutingType.Y); - } - //childrenRWLock.ExitReadLock (); - break; + } finally { + childrenRWLock.ExitReadLock (); } - childrenRWLock.ExitReadLock (); } #endregion public virtual void OnChildLayoutChanges (object sender, LayoutingEventArgs arg) @@ -177,7 +183,7 @@ namespace Crow } DbgLogger.EndEvent(DbgEvtType.GOOnChildLayoutChange); } - //TODO: x,y position should be taken in account for computation of width and height + //TODO: x,y position should be taken in account for computation of width and height + Layout mutex? void resetChildrenMaxSize(){ largestChild = null; tallestChild = null; @@ -186,62 +192,63 @@ namespace Crow protected virtual void searchLargestChild (bool forceMeasure = false) { DbgLogger.StartEvent (DbgEvtType.GOSearchLargestChild, this); - childrenRWLock.EnterReadLock (); - largestChild = null; - contentSize.Width = 0; - for (int i = 0; i < Children.Count; i++) { - if (!Children [i].IsVisible) - continue; - int cw = 0; - if (forceMeasure) - cw = Children [i].measureRawSize (LayoutingType.Width); - else if (Children[i].Width.IsRelativeToParent || Children [i].RegisteredLayoutings.HasFlag (LayoutingType.Width)) - continue; - else - cw = Children [i].Slot.Width; - if (cw > contentSize.Width) { - contentSize.Width = cw; - largestChild = Children [i]; + try { + + largestChild = null; + contentSize.Width = 0; + for (int i = 0; i < Children.Count; i++) { + if (!Children [i].IsVisible) + continue; + int cw = 0; + if (forceMeasure) + cw = Children [i].measureRawSize (LayoutingType.Width); + else if (Children[i].Width.IsRelativeToParent || Children [i].RegisteredLayoutings.HasFlag (LayoutingType.Width)) + continue; + else + cw = Children [i].Slot.Width; + if (cw > contentSize.Width) { + contentSize.Width = cw; + largestChild = Children [i]; + } } + if (largestChild == null && !forceMeasure) + searchLargestChild (true); + } finally { + childrenRWLock.ExitReadLock (); + DbgLogger.EndEvent (DbgEvtType.GOSearchLargestChild); } - if (largestChild == null && !forceMeasure) - searchLargestChild (true); - - childrenRWLock.ExitReadLock (); - - DbgLogger.EndEvent (DbgEvtType.GOSearchLargestChild); } protected virtual void searchTallestChild (bool forceMeasure = false) { DbgLogger.StartEvent (DbgEvtType.GOSearchTallestChild, this); - childrenRWLock.EnterReadLock (); - tallestChild = null; - contentSize.Height = 0; - for (int i = 0; i < Children.Count; i++) { - if (!Children [i].IsVisible) - continue; - int ch = 0; - if (forceMeasure) - ch = Children [i].measureRawSize (LayoutingType.Height); - else if (Children[i].Height.IsRelativeToParent || Children [i].RegisteredLayoutings.HasFlag (LayoutingType.Height)) - continue; - else - ch = Children [i].Slot.Height; - if (ch > contentSize.Height) { - contentSize.Height = ch; - tallestChild = Children [i]; + try { + tallestChild = null; + contentSize.Height = 0; + for (int i = 0; i < Children.Count; i++) { + if (!Children [i].IsVisible) + continue; + int ch = 0; + if (forceMeasure) + ch = Children [i].measureRawSize (LayoutingType.Height); + else if (Children[i].Height.IsRelativeToParent || Children [i].RegisteredLayoutings.HasFlag (LayoutingType.Height)) + continue; + else + ch = Children [i].Slot.Height; + if (ch > contentSize.Height) { + contentSize.Height = ch; + tallestChild = Children [i]; + } } + if (tallestChild == null && !forceMeasure) + searchTallestChild (true); + } finally { + childrenRWLock.ExitReadLock (); + DbgLogger.EndEvent (DbgEvtType.GOSearchTallestChild); } - if (tallestChild == null && !forceMeasure) - searchTallestChild (true); - - childrenRWLock.ExitReadLock (); - - DbgLogger.EndEvent (DbgEvtType.GOSearchTallestChild); } } } diff --git a/Crow/src/Widgets/GroupBase.cs b/Crow/src/Widgets/GroupBase.cs index 5784bc29..cac017c7 100644 --- a/Crow/src/Widgets/GroupBase.cs +++ b/Crow/src/Widgets/GroupBase.cs @@ -20,14 +20,15 @@ namespace Crow if (base.FindByDesignID (designID, out go)) return true; childrenRWLock.EnterReadLock (); - foreach (Widget w in Children) { - if (!w.FindByDesignID (designID, out go)) - continue; + try { + foreach (Widget w in Children) { + if (w.FindByDesignID (designID, out go)) + return true; + } + return false; + } finally { childrenRWLock.ExitReadLock (); - return true; } - childrenRWLock.ExitReadLock (); - return false; } public override void getIML (System.Xml.XmlDocument doc, System.Xml.XmlNode parentElem) { @@ -73,12 +74,13 @@ namespace Crow } childrenRWLock.EnterWriteLock (); - - Children.Remove(child); - child.Parent = null; - child.LogicalParent = null; - - childrenRWLock.ExitWriteLock (); + try { + Children.Remove(child); + child.Parent = null; + child.LogicalParent = null; + } finally { + childrenRWLock.ExitWriteLock (); + } } public virtual void DeleteChild(Widget child) { @@ -91,11 +93,12 @@ namespace Crow return; } childrenRWLock.EnterWriteLock (); - - g.Parent = this; - Children.Insert (idx, g); - - childrenRWLock.ExitWriteLock (); + try { + g.Parent = this; + Children.Insert (idx, g); + } finally { + childrenRWLock.ExitWriteLock (); + } } public virtual void RemoveChild (int idx) { RemoveChild (children[idx]); @@ -107,53 +110,57 @@ namespace Crow { childrenRWLock.EnterWriteLock (); - while (Children.Count > 0) { - Widget g = Children [Children.Count - 1]; - Children.RemoveAt (Children.Count - 1); - g.Dispose (); + try { + while (Children.Count > 0) { + Widget g = Children [Children.Count - 1]; + Children.RemoveAt (Children.Count - 1); + g.Dispose (); + } + } finally { + childrenRWLock.ExitWriteLock (); } - - childrenRWLock.ExitWriteLock (); } public override void OnDataSourceChanged (object sender, DataSourceChangeEventArgs e) { base.OnDataSourceChanged (this, e); + + childrenRWLock.EnterReadLock (); try { - childrenRWLock.EnterReadLock (); foreach (Widget g in Children) { if (g.localDataSourceIsNull & g.localLogicalParentIsNull) g.OnDataSourceChanged (g, e); } + } finally { childrenRWLock.ExitReadLock (); - } catch (Exception) { - childrenRWLock.ExitReadLock (); - throw; } } public void putWidgetOnTop(Widget w) { - if (Children.Contains(w)) - { - childrenRWLock.EnterWriteLock (); - - Children.Remove (w); - Children.Add (w); - + childrenRWLock.EnterWriteLock (); + try { + if (Children.Contains(w)) + { + Children.Remove (w); + Children.Add (w); + } + } finally { childrenRWLock.ExitWriteLock (); } } + public void putWidgetOnBottom(Widget w) { - if (Children.Contains(w)) - { - childrenRWLock.EnterWriteLock (); - - Children.Remove (w); - Children.Insert (0, w); - + childrenRWLock.EnterWriteLock (); + try { + if (Children.Contains(w)) + { + Children.Remove (w); + Children.Insert (0, w); + } + } finally { childrenRWLock.ExitWriteLock (); - } + } } #region GraphicObject overrides @@ -165,15 +172,18 @@ namespace Crow childrenRWLock.EnterReadLock (); - foreach (Widget w in Children) { - tmp = w.FindByName (nameToFind); - if (tmp != null) - break; - } + try { - childrenRWLock.ExitReadLock (); + foreach (Widget w in Children) { + tmp = w.FindByName (nameToFind); + if (tmp != null) + break; + } + return tmp; - return tmp; + } finally { + childrenRWLock.ExitReadLock (); + } } public override T FindByType () { @@ -195,13 +205,18 @@ namespace Crow } public override bool Contains (Widget goToFind) { - foreach (Widget w in Children) { - if (w == goToFind) - return true; - if (w.Contains (goToFind)) - return true; + childrenRWLock.EnterReadLock (); + try { + foreach (Widget w in Children) { + if (w == goToFind) + return true; + if (w.Contains (goToFind)) + return true; + } + return false; + } finally { + childrenRWLock.ExitReadLock (); } - return false; } protected override void onDraw (Context gr) @@ -217,20 +232,14 @@ namespace Crow gr.Clip (); } + childrenRWLock.EnterReadLock (); try { - childrenRWLock.EnterReadLock (); - for (int i = 0; i < Children.Count; i++) - Children[i].Paint (gr); - + Children[i].Paint (gr); + } finally { childrenRWLock.ExitReadLock (); } - catch (System.Exception) - { - childrenRWLock.ExitReadLock (); - throw; - } if (ClipToClientRect) gr.Restore (); @@ -257,17 +266,18 @@ namespace Crow } childrenRWLock.EnterReadLock (); - - foreach (Widget c in Children) { - if (!c.IsVisible) - continue; - if (Clipping.Contains (c.Slot + ClientRectangle.Position) == RegionOverlap.Out) - continue; - c.Paint (gr); + try { + foreach (Widget c in Children) { + if (!c.IsVisible) + continue; + if (Clipping.Contains (c.Slot + ClientRectangle.Position) == RegionOverlap.Out) + continue; + c.Paint (gr); + } + } finally { + childrenRWLock.ExitReadLock (); } - childrenRWLock.ExitReadLock (); - #if DEBUG_CLIP_RECTANGLE /*gr.LineWidth = 1; gr.SetSourceColor(Color.DarkMagenta.AdjustAlpha (0.8)); @@ -290,14 +300,16 @@ namespace Crow base.checkHoverWidget (e);//TODO:check if not possible to put it at beginning of meth to avoid doubled check to DropTarget. if (!childrenRWLock.TryEnterReadLock (10)) return; - for (int i = Children.Count - 1; i >= 0; i--) { - if (Children[i].MouseIsIn (e.Position)) { - Children[i].checkHoverWidget (e); - childrenRWLock.ExitReadLock (); - return; + try { + for (int i = Children.Count - 1; i >= 0; i--) { + if (Children[i].MouseIsIn (e.Position)) { + Children[i].checkHoverWidget (e); + return; + } } + } finally { + childrenRWLock.ExitReadLock (); } - childrenRWLock.ExitReadLock (); } #endregion @@ -305,9 +317,12 @@ namespace Crow { if (disposing) { childrenRWLock.EnterReadLock (); - foreach (Widget c in Children) - c.Dispose (); - childrenRWLock.ExitReadLock (); + try { + foreach (Widget c in Children) + c.Dispose (); + } finally { + childrenRWLock.ExitReadLock (); + } } base.Dispose (disposing); } diff --git a/Crow/src/Widgets/Label.cs b/Crow/src/Widgets/Label.cs index 17544ec7..31127ddd 100644 --- a/Crow/src/Widgets/Label.cs +++ b/Crow/src/Widgets/Label.cs @@ -611,9 +611,12 @@ namespace Crow if (!System.Threading.Monitor.TryEnter (linesMutex)) return false; } - bool result = base.UpdateLayout (layoutType); - System.Threading.Monitor.Exit (linesMutex); - return result; + try { + bool result = base.UpdateLayout (layoutType); + return result; + } finally { + System.Threading.Monitor.Exit (linesMutex); + } } public override int measureRawSize(LayoutingType lt) { diff --git a/Crow/src/Widgets/ScrollingStack.cs b/Crow/src/Widgets/ScrollingStack.cs index 959a4550..b00bb211 100644 --- a/Crow/src/Widgets/ScrollingStack.cs +++ b/Crow/src/Widgets/ScrollingStack.cs @@ -114,10 +114,8 @@ namespace Crow { gr.Clip (); } - try - { - childrenRWLock.EnterReadLock (); - + childrenRWLock.EnterReadLock (); + try { for (int i = Scroll; i < Children.Count && i < Scroll + visibleItems; i++) { if (!Children[i].IsVisible) continue; @@ -125,13 +123,8 @@ namespace Crow { continue;*/ Children[i].Paint (gr); } - - childrenRWLock.ExitReadLock (); - } - catch (System.Exception) - { + } finally { childrenRWLock.ExitReadLock (); - throw; } if (ClipToClientRect) @@ -159,17 +152,18 @@ namespace Crow { } childrenRWLock.EnterReadLock (); - - for (int i = Scroll; i < Children.Count && i < Scroll + visibleItems; i++) { - if (!Children[i].IsVisible) - continue; - /*if (Clipping.Contains (c.Slot + ClientRectangle.Position) == RegionOverlap.Out) - continue;*/ - Children[i].Paint (gr); + try { + for (int i = Scroll; i < Children.Count && i < Scroll + visibleItems; i++) { + if (!Children[i].IsVisible) + continue; + /*if (Clipping.Contains (c.Slot + ClientRectangle.Position) == RegionOverlap.Out) + continue;*/ + Children[i].Paint (gr); + } + } finally { + childrenRWLock.ExitReadLock (); } - childrenRWLock.ExitReadLock (); - #if DEBUG_CLIP_RECTANGLE /*gr.LineWidth = 1; gr.SetSourceColor(Color.DarkMagenta.AdjustAlpha (0.8)); @@ -191,14 +185,16 @@ namespace Crow { base.checkHoverWidget (e);//TODO:check if not possible to put it at beginning of meth to avoid doubled check to DropTarget. if (!childrenRWLock.TryEnterReadLock (10)) return; - for (int i = Children.Count - 1; i >= 0; i--) { - if (Children[i].MouseIsIn (e.Position)) { - Children[i].checkHoverWidget (e); - childrenRWLock.ExitReadLock (); - return; + try { + for (int i = Children.Count - 1; i >= 0; i--) { + if (Children[i].MouseIsIn (e.Position)) { + Children[i].checkHoverWidget (e); + return; + } } + } finally { + childrenRWLock.ExitReadLock (); } - childrenRWLock.ExitReadLock (); } /// Process scrolling vertically, or if shift is down, vertically public override void onMouseWheel (object sender, MouseWheelEventArgs e) { diff --git a/Crow/src/Widgets/Table.cs b/Crow/src/Widgets/Table.cs index 27cfb963..1427e9ba 100644 --- a/Crow/src/Widgets/Table.cs +++ b/Crow/src/Widgets/Table.cs @@ -265,29 +265,30 @@ namespace Crow Column c = Columns[cIdx]; childrenRWLock.EnterReadLock (); - - c.LargestChild = null; - int largestWidth = 0; - for (int i = 1; i < Children.Count; i++) { - TableRow row = Children[i] as TableRow; - if (!row.IsVisible) - continue; - int cw = row.Children [cIdx]. measureRawSize (LayoutingType.Width); - if (cw > largestWidth) { - largestWidth = cw; - c.LargestChild = row.Children [cIdx]; + try { + c.LargestChild = null; + int largestWidth = 0; + for (int i = 1; i < Children.Count; i++) { + TableRow row = Children[i] as TableRow; + if (!row.IsVisible) + continue; + int cw = row.Children [cIdx]. measureRawSize (LayoutingType.Width); + if (cw > largestWidth) { + largestWidth = cw; + c.LargestChild = row.Children [cIdx]; + } } + if (HeaderRow.Children[cIdx].Slot.Width > largestWidth) { + c.LargestChild = HeaderRow.Children[cIdx]; + return; + } + HeaderRow.Children[cIdx].Slot.Width = largestWidth; + } finally { + childrenRWLock.ExitReadLock (); + DbgLogger.EndEvent (DbgEvtType.GOSearchLargestChild); } - childrenRWLock.ExitReadLock (); - - if (HeaderRow.Children[cIdx].Slot.Width > largestWidth) { - c.LargestChild = HeaderRow.Children[cIdx]; - return; - } - HeaderRow.Children[cIdx].Slot.Width = largestWidth; //HeaderRow.adjustStretchedGo (LayoutingType.Width); - DbgLogger.EndEvent (DbgEvtType.GOSearchLargestChild); } int splitIndex = -1; const int minColumnSize = 10; diff --git a/Crow/src/Widgets/TableRow.cs b/Crow/src/Widgets/TableRow.cs index 1ce02c15..1f646bcb 100644 --- a/Crow/src/Widgets/TableRow.cs +++ b/Crow/src/Widgets/TableRow.cs @@ -45,11 +45,13 @@ namespace Crow return; } childrenRWLock.EnterWriteLock (); - - g.Parent = this; - Children.Insert (idx, g); - - childrenRWLock.ExitWriteLock (); + + try { + g.Parent = this; + Children.Insert (idx, g); + } finally { + childrenRWLock.ExitWriteLock (); + } if (g.LastSlots.Height > contentSize.Height) { tallestChild = g; @@ -70,12 +72,13 @@ namespace Crow } childrenRWLock.EnterWriteLock (); - - Children.Remove(child); - child.Parent = null; - child.LogicalParent = null; - - childrenRWLock.ExitWriteLock (); + try { + Children.Remove(child); + child.Parent = null; + child.LogicalParent = null; + } finally { + childrenRWLock.ExitWriteLock (); + } if (child == tallestChild && Height == Measure.Fit) searchTallestChild (); @@ -86,16 +89,17 @@ namespace Crow public override void ClearChildren() { childrenRWLock.EnterWriteLock (); - - while (Children.Count > 0) { - Widget g = Children [Children.Count - 1]; - g.LayoutChanged -= OnChildLayoutChanges; - Children.RemoveAt (Children.Count - 1); - g.Dispose (); + try { + while (Children.Count > 0) { + Widget g = Children [Children.Count - 1]; + g.LayoutChanged -= OnChildLayoutChanges; + Children.RemoveAt (Children.Count - 1); + g.Dispose (); + } + } finally { + childrenRWLock.ExitWriteLock (); } - childrenRWLock.ExitWriteLock (); - resetChildrenMaxSize (); RegisterForLayouting (LayoutingType.Sizing); @@ -111,21 +115,20 @@ namespace Crow { base.OnLayoutChanges (layoutType); - childrenRWLock.EnterReadLock (); //position smaller objects in group when group size is fit - switch (layoutType) { - case LayoutingType.Height: + if (layoutType == LayoutingType.Height) { childrenRWLock.EnterReadLock (); - foreach (Widget c in Children) { - if (c.Height.IsRelativeToParent) - c.RegisterForLayouting (LayoutingType.Height); - else - c.RegisterForLayouting (LayoutingType.Y); + try { + foreach (Widget c in Children) { + if (c.Height.IsRelativeToParent) + c.RegisterForLayouting (LayoutingType.Height); + else + c.RegisterForLayouting (LayoutingType.Y); + } + } finally { + childrenRWLock.ExitReadLock (); } - childrenRWLock.ExitReadLock (); - break; } - childrenRWLock.ExitReadLock (); } public virtual void OnChildLayoutChanges (object sender, LayoutingEventArgs arg) { @@ -152,32 +155,32 @@ namespace Crow protected virtual void searchTallestChild (bool forceMeasure = false) { DbgLogger.StartEvent (DbgEvtType.GOSearchTallestChild, this); - childrenRWLock.EnterReadLock (); - tallestChild = null; - contentSize.Height = 0; - for (int i = 0; i < Children.Count; i++) { - if (!Children [i].IsVisible) - continue; - int ch = 0; - if (forceMeasure) - ch = Children [i].measureRawSize (LayoutingType.Height); - else if (Children [i].RegisteredLayoutings.HasFlag (LayoutingType.Height)) - continue; - else - ch = Children [i].Slot.Height; - if (ch > contentSize.Height) { - contentSize.Height = ch; - tallestChild = Children [i]; + try { + tallestChild = null; + contentSize.Height = 0; + for (int i = 0; i < Children.Count; i++) { + if (!Children [i].IsVisible) + continue; + int ch = 0; + if (forceMeasure) + ch = Children [i].measureRawSize (LayoutingType.Height); + else if (Children [i].RegisteredLayoutings.HasFlag (LayoutingType.Height)) + continue; + else + ch = Children [i].Slot.Height; + if (ch > contentSize.Height) { + contentSize.Height = ch; + tallestChild = Children [i]; + } } + if (tallestChild == null && !forceMeasure) + searchTallestChild (true); + } finally { + childrenRWLock.ExitReadLock (); + DbgLogger.EndEvent (DbgEvtType.GOSearchTallestChild); } - if (tallestChild == null && !forceMeasure) - searchTallestChild (true); - - childrenRWLock.ExitReadLock (); - - DbgLogger.EndEvent (DbgEvtType.GOSearchTallestChild); } void resetChildrenMaxSize(){ tallestChild = null; diff --git a/Crow/src/Widgets/TemplatedGroup.cs b/Crow/src/Widgets/TemplatedGroup.cs index f489ca96..90c23553 100644 --- a/Crow/src/Widgets/TemplatedGroup.cs +++ b/Crow/src/Widgets/TemplatedGroup.cs @@ -365,14 +365,14 @@ namespace Crow { try { loadPage (data, itemsContainer, dataTest); } catch (Exception ex) { - while (Monitor.IsEntered (IFace.UpdateMutex)) +/* while (Monitor.IsEntered (IFace.UpdateMutex)) Monitor.Exit (IFace.UpdateMutex); while (Monitor.IsEntered (IFace.LayoutMutex)) - Monitor.Exit (IFace.LayoutMutex); + Monitor.Exit (IFace.LayoutMutex);*/ System.Diagnostics.Debug.WriteLine ("loading thread aborted: " + ex.ToString()); + } finally { + DbgLogger.EndEvent (DbgEvtType.TGLoadingThread); } - - DbgLogger.EndEvent (DbgEvtType.TGLoadingThread); } // //if (!ItemTemplates.ContainsKey ("default")) // // ItemTemplates ["default"] = Interface.GetItemTemplate (ItemTemplate); @@ -392,7 +392,7 @@ namespace Crow { DbgLogger.StartEvent (DbgEvtType.TGCancelLoadingThread, this); - int updateMx = 0, layoutMx = 0; + /*int updateMx = 0, layoutMx = 0; while (Monitor.IsEntered (IFace.UpdateMutex)) { Monitor.Exit (IFace.UpdateMutex); @@ -401,14 +401,14 @@ namespace Crow { while (Monitor.IsEntered (IFace.LayoutMutex)) { Monitor.Exit (IFace.LayoutMutex); layoutMx++; - } + }*/ loadingThread.Cancel (); - for (int i = 0; i < layoutMx; i++) + /*for (int i = 0; i < layoutMx; i++) Monitor.Enter (IFace.LayoutMutex); for (int i = 0; i < updateMx; i++) - Monitor.Enter (IFace.UpdateMutex); + Monitor.Enter (IFace.UpdateMutex);*/ loadingThread = null; @@ -500,6 +500,7 @@ namespace Crow { } } + try { g = iTemp.CreateInstance(); #if DESIGN_MODE g.design_isTGItem = true; @@ -508,7 +509,9 @@ namespace Crow { // if (isPaged) g.LogicalParent = this; g.MouseClick += itemClick; - Monitor.Exit (IFace.UpdateMutex); + } finally { + Monitor.Exit (IFace.UpdateMutex); + } if (iTemp.Expand != null) { IToggle toggle = g as IToggle; diff --git a/Crow/src/Widgets/Widget.cs b/Crow/src/Widgets/Widget.cs index dbed07b7..d47675b8 100644 --- a/Crow/src/Widgets/Widget.cs +++ b/Crow/src/Widgets/Widget.cs @@ -332,7 +332,7 @@ namespace Crow /// Parent in the graphic tree, used for rendering and layouting /// [XmlIgnore]public virtual ILayoutable Parent { - get { return parent; } + get => parent; set { if (parent == value) return; @@ -1012,12 +1012,12 @@ namespace Crow if (value != null) rootDataLevel = true; - DbgLogger.StartEvent(DbgEvtType.GOLockUpdate, this); - lock (IFace.UpdateMutex) { + /*DbgLogger.StartEvent(DbgEvtType.GOLockUpdate, this); + lock (IFace.UpdateMutex) {*/ OnDataSourceChanged (this, dse); NotifyValueChangedAuto (DataSource); - } - DbgLogger.EndEvent (DbgEvtType.GOLockUpdate); + /*} + DbgLogger.EndEvent (DbgEvtType.GOLockUpdate);*/ } get { return rootDataLevel ? dataSource : dataSource == null ? @@ -1456,8 +1456,8 @@ namespace Crow parentRWLock.EnterReadLock (); if (parent != null) { - Parent.RegisterClip (LastPaintedSlot); - Parent.RegisterClip (Slot); + parent.RegisterClip (LastPaintedSlot); + parent.RegisterClip (Slot); } parentRWLock.ExitReadLock (); @@ -1473,30 +1473,26 @@ namespace Crow return; } DbgLogger.StartEvent(DbgEvtType.GORegisterClip, this); - Rectangle cb = ClientRectangle; - Rectangle r = clip + cb.Position; - if (r.Right > cb.Right) - r.Width -= r.Right - cb.Right; - if (r.Bottom > cb.Bottom) - r.Height -= r.Bottom - cb.Bottom; - if (r.Width < 0 || r.Height < 0) { - //Debug.WriteLine ($"Invalid clip: {clip}:{r} hnd:{this}");//\n{Environment.StackTrace}"); - DbgLogger.EndEvent (DbgEvtType.GORegisterClip); - return; - } - if (cacheEnabled && !IsDirty) - Clipping.UnionRectangle (r); - if (Parent == null) { - DbgLogger.EndEvent (DbgEvtType.GORegisterClip); - return; - } - Widget p = Parent as Widget; - if (p?.IsDirty == true && p?.CacheEnabled == true) { + try { + Rectangle cb = ClientRectangle; + Rectangle r = clip + cb.Position; + if (r.Right > cb.Right) + r.Width -= r.Right - cb.Right; + if (r.Bottom > cb.Bottom) + r.Height -= r.Bottom - cb.Bottom; + if (r.Width < 0 || r.Height < 0) + return; + if (cacheEnabled && !IsDirty) + Clipping.UnionRectangle (r); + if (Parent == null) + return; + Widget p = Parent as Widget; + if (p?.IsDirty == true && p?.CacheEnabled == true) + return; + Parent.RegisterClip (r + Slot.Position); + } finally { DbgLogger.EndEvent (DbgEvtType.GORegisterClip); - return; } - Parent.RegisterClip (r + Slot.Position); - DbgLogger.EndEvent (DbgEvtType.GORegisterClip); } /// Full update, if width or height is 'Fit' a layouting is requested, and a redraw is done in any case. [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -1580,47 +1576,47 @@ namespace Crow if (Parent == null) return; DbgLogger.StartEvent (DbgEvtType.GOLockLayouting, this); - lock (IFace.LayoutMutex) { - //prevent queueing same LayoutingType for this - layoutType &= (~RegisteredLayoutings); + try { + lock (IFace.LayoutMutex) { + //prevent queueing same LayoutingType for this + layoutType &= (~RegisteredLayoutings); - if (layoutType == LayoutingType.None) { - DbgLogger.EndEvent (DbgEvtType.GOLockLayouting); - return; - } - //dont set position for stretched item - if (Width == Measure.Stretched) - layoutType &= (~LayoutingType.X); - if (Height == Measure.Stretched) - layoutType &= (~LayoutingType.Y); + if (layoutType == LayoutingType.None) + return; + + //dont set position for stretched item + if (Width == Measure.Stretched) + layoutType &= (~LayoutingType.X); + if (Height == Measure.Stretched) + layoutType &= (~LayoutingType.Y); - if (!ArrangeChildren) - layoutType &= (~LayoutingType.ArrangeChildren); + if (!ArrangeChildren) + layoutType &= (~LayoutingType.ArrangeChildren); - //apply constraints depending on parent type - Parent.ChildrenLayoutingConstraints (this, ref layoutType); + //apply constraints depending on parent type + Parent.ChildrenLayoutingConstraints (this, ref layoutType); -// //prevent queueing same LayoutingType for this - layoutType &= (~RegisteredLayoutings); + // //prevent queueing same LayoutingType for this + layoutType &= (~RegisteredLayoutings); - if (layoutType == LayoutingType.None) { - DbgLogger.EndEvent (DbgEvtType.GOLockLayouting); - return; - } + if (layoutType == LayoutingType.None) + return; - //enqueue LQI LayoutingTypes separately - if (layoutType.HasFlag (LayoutingType.Width)) - IFace.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Width, this)); - if (layoutType.HasFlag (LayoutingType.Height)) - IFace.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Height, this)); - if (layoutType.HasFlag (LayoutingType.X)) - IFace.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.X, this)); - if (layoutType.HasFlag (LayoutingType.Y)) - IFace.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Y, this)); - if (layoutType.HasFlag (LayoutingType.ArrangeChildren)) - IFace.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.ArrangeChildren, this)); + //enqueue LQI LayoutingTypes separately + if (layoutType.HasFlag (LayoutingType.Width)) + IFace.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Width, this)); + if (layoutType.HasFlag (LayoutingType.Height)) + IFace.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Height, this)); + if (layoutType.HasFlag (LayoutingType.X)) + IFace.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.X, this)); + if (layoutType.HasFlag (LayoutingType.Y)) + IFace.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Y, this)); + if (layoutType.HasFlag (LayoutingType.ArrangeChildren)) + IFace.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.ArrangeChildren, this)); + } + } finally { + DbgLogger.EndEvent (DbgEvtType.GOLockLayouting); } - DbgLogger.EndEvent (DbgEvtType.GOLockLayouting); } /// trigger dependant sizing component update @@ -1888,11 +1884,11 @@ namespace Crow DbgLogger.EndEvent (DbgEvtType.GOPaint); return; } - lock (this) { + //lock (this) { if (cacheEnabled) { if (Slot.Width > Interface.MaxCacheSize || Slot.Height > Interface.MaxCacheSize) cacheEnabled = false; - } + } if (cacheEnabled) { if (IsDirty) { @@ -1915,9 +1911,10 @@ namespace Crow if (!IsEnabled) paintDisabled (ctx, rb); - } + } + LastPaintedSlot = Slot; - } + //} Painted.Raise (this, null); DbgLogger.EndEvent (DbgEvtType.GOPaint); diff --git a/Crow/src/Widgets/Window.cs b/Crow/src/Widgets/Window.cs index f7bd5144..07b575b0 100644 --- a/Crow/src/Widgets/Window.cs +++ b/Crow/src/Widgets/Window.cs @@ -154,7 +154,7 @@ namespace Crow /// mouse delta on the Y axis /// Current Direction of the operation, none for moving, other value for resizing in the given direction protected void moveAndResize (int XDelta, int YDelta, Direction currentDirection = (Direction)0) { - lock (IFace.UpdateMutex) { + //lock (IFace.UpdateMutex) { int currentLeft = this.Left; int currentTop = this.Top; int currentWidth, currentHeight; @@ -223,7 +223,7 @@ namespace Crow this.Width = currentWidth + XDelta; break; } - } + //} } bool maySize => sizingHandle == null ? false : resizable & sizingHandle.IsHover; @@ -386,15 +386,15 @@ namespace Crow if (Parent is Interface) (Parent as Interface).DeleteWidget (this); else { - Widget p = Parent as Widget; - if (p is Group g) { - lock (IFace.UpdateMutex) { - RegisterClip (p.ScreenCoordinates (p.LastPaintedSlot)); - g.DeleteChild (this); - } - //(Parent as Group).RegisterForRedraw (); - } else if (Parent is Container c) - c.Child = null; + lock (IFace.UpdateMutex) { + Widget p = Parent as Widget; + if (p is Group g) { + RegisterClip (p.ScreenCoordinates (p.LastPaintedSlot)); + g.DeleteChild (this); + //(Parent as Group).RegisterForRedraw (); + } else if (Parent is Container c) + c.Child = null; + } } } diff --git a/Crow/src/Widgets/Wrapper.cs b/Crow/src/Widgets/Wrapper.cs index ead1f533..19243ba0 100644 --- a/Crow/src/Widgets/Wrapper.cs +++ b/Crow/src/Widgets/Wrapper.cs @@ -109,27 +109,27 @@ namespace Crow int largestChild = 0; childrenRWLock.EnterReadLock(); - - foreach (Widget c in Children) { - if (!c.Visible) - continue; - if (c.Height.IsRelativeToParent && - c.RegisteredLayoutings.HasFlag (LayoutingType.Height)) { - childrenRWLock.ExitReadLock(); - return -1; + try { + foreach (Widget c in Children) { + if (!c.IsVisible) + continue; + if (c.Height.IsRelativeToParent && + c.RegisteredLayoutings.HasFlag (LayoutingType.Height)) { + return -1; + } + if (dy + c.Slot.Height > ClientRectangle.Height) { + dy = 0; + tmp += largestChild + Spacing; + largestChild = c.Slot.Width; + } else if (largestChild < c.Slot.Width) + largestChild = c.Slot.Width; + + dy += c.Slot.Height + Spacing; } - if (dy + c.Slot.Height > ClientRectangle.Height) { - dy = 0; - tmp += largestChild + Spacing; - largestChild = c.Slot.Width; - } else if (largestChild < c.Slot.Width) - largestChild = c.Slot.Width; - - dy += c.Slot.Height + Spacing; + } finally { + childrenRWLock.ExitReadLock (); } - childrenRWLock.ExitReadLock (); - if (dy == 0) tmp -= Spacing; return tmp + largestChild + 2 * Margin; @@ -144,27 +144,27 @@ namespace Crow int tallestChild = 0; childrenRWLock.EnterReadLock(); + try { + foreach (Widget c in Children) { + if (!c.IsVisible) + continue; + if (c.Width.IsRelativeToParent && + c.RegisteredLayoutings.HasFlag (LayoutingType.Width)) { + return -1; + } + if (dx + c.Slot.Width > ClientRectangle.Width) { + dx = 0; + tmp += tallestChild + Spacing; + tallestChild = c.Slot.Height; + } else if (tallestChild < c.Slot.Height) + tallestChild = c.Slot.Height; - foreach (Widget c in Children) { - if (!c.Visible) - continue; - if (c.Width.IsRelativeToParent && - c.RegisteredLayoutings.HasFlag (LayoutingType.Width)) { - childrenRWLock.ExitReadLock(); - return -1; + dx += c.Slot.Width + Spacing; } - if (dx + c.Slot.Width > ClientRectangle.Width) { - dx = 0; - tmp += tallestChild + Spacing; - tallestChild = c.Slot.Height; - } else if (tallestChild < c.Slot.Height) - tallestChild = c.Slot.Height; - - dx += c.Slot.Width + Spacing; + } finally { + childrenRWLock.ExitReadLock(); } - childrenRWLock.ExitReadLock(); - if (dx == 0) tmp -= Spacing; return tmp + tallestChild + 2 * Margin; @@ -192,30 +192,35 @@ namespace Crow } public override void OnLayoutChanges (LayoutingType layoutType) { - switch (layoutType) { - case LayoutingType.Width: - foreach (Widget c in Children) { - if (c.Width.IsRelativeToParent) - c.RegisterForLayouting (LayoutingType.Width); - } - if (Height == Measure.Fit) - RegisterForLayouting (LayoutingType.Height); - RegisterForLayouting (LayoutingType.X); - break; - case LayoutingType.Height: - foreach (Widget c in Children) { - if (c.Height.IsRelativeToParent) - c.RegisterForLayouting (LayoutingType.Height); + childrenRWLock.EnterReadLock(); + try { + switch (layoutType) { + case LayoutingType.Width: + foreach (Widget c in Children) { + if (c.Width.IsRelativeToParent) + c.RegisterForLayouting (LayoutingType.Width); + } + if (Height == Measure.Fit) + RegisterForLayouting (LayoutingType.Height); + RegisterForLayouting (LayoutingType.X); + break; + case LayoutingType.Height: + foreach (Widget c in Children) { + if (c.Height.IsRelativeToParent) + c.RegisterForLayouting (LayoutingType.Height); + } + if (Width == Measure.Fit) + RegisterForLayouting (LayoutingType.Width); + RegisterForLayouting (LayoutingType.Y); + break; + default: + return; } - if (Width == Measure.Fit) - RegisterForLayouting (LayoutingType.Width); - RegisterForLayouting (LayoutingType.Y); - break; - default: - return; + RegisterForLayouting (LayoutingType.ArrangeChildren); + raiseLayoutChanged (layoutType); + } finally { + childrenRWLock.ExitReadLock(); } - RegisterForLayouting (LayoutingType.ArrangeChildren); - raiseLayoutChanged (layoutType); } #endregion } diff --git a/Samples/DebugLogAnalyzer/src/DbgEventWidget.cs b/Samples/DebugLogAnalyzer/src/DbgEventWidget.cs index 6af3f6df..b369d248 100644 --- a/Samples/DebugLogAnalyzer/src/DbgEventWidget.cs +++ b/Samples/DebugLogAnalyzer/src/DbgEventWidget.cs @@ -30,12 +30,15 @@ namespace Crow long ticksPerPixel; double pixelPerTick; + object dataMutex = new object(); + public DbgEvent Event { get => evt; set { if (evt == value) return; - evt = value; + lock (dataMutex) + evt = value; updatePixelPerTicks (); NotifyValueChangedAuto (evt); RegisterForRedraw (); @@ -46,6 +49,8 @@ namespace Crow private set { if (hoverEvt == value) return; + lock (dataMutex) + evt = value; hoverEvt = value; NotifyValueChangedAuto (hoverEvt); } @@ -83,24 +88,27 @@ namespace Crow protected override void onDraw (Context gr) { - if (Event == null) { - base.onDraw (gr); - return; - } + lock (dataMutex) { + + if (Event == null) { + base.onDraw (gr); + return; + } - gr.LineWidth = 1; - gr.SetDash (new double [] { 1.0, 3.0 }, 0); + gr.LineWidth = 1; + gr.SetDash (new double [] { 1.0, 3.0 }, 0); - Rectangle cb = ClientRectangle; + Rectangle cb = ClientRectangle; - if (Event.Duration == 0) { - gr.SetSource (Event.Color); - gr.Rectangle (cb); - gr.Fill (); - return; - } + if (Event.Duration == 0) { + gr.SetSource (Event.Color); + gr.Rectangle (cb); + gr.Fill (); + return; + } - drawEvent (gr, cb.Height, Event); + drawEvent (gr, cb.Height, Event); + } } void drawEvent (Context ctx, int h, DbgEvent dbge) { diff --git a/Samples/DebugLogAnalyzer/src/DbgLogViewer.cs b/Samples/DebugLogAnalyzer/src/DbgLogViewer.cs index d39cc62a..251090ef 100644 --- a/Samples/DebugLogAnalyzer/src/DbgLogViewer.cs +++ b/Samples/DebugLogAnalyzer/src/DbgLogViewer.cs @@ -481,7 +481,7 @@ namespace Crow if (lastTick >= 0 && hoverTick >= 0) ScrollX += lastTick - hoverTick; if (lastLine >= 0 && hoverLine >= 0) - ScrollY += lastLine - hoverLine; + ScrollY += lastLine - hoverLine; updateMouseLocalPos (e.Position); } else { HoverWidget = (hoverLine < 0 || hoverLine >= widgets.Count) ? null : widgets [hoverLine]; diff --git a/Samples/DebugLogAnalyzer/src/DebugInterface.cs b/Samples/DebugLogAnalyzer/src/DebugInterface.cs index 1653f163..64de2163 100644 --- a/Samples/DebugLogAnalyzer/src/DebugInterface.cs +++ b/Samples/DebugLogAnalyzer/src/DebugInterface.cs @@ -43,13 +43,28 @@ namespace Crow } catch (System.Exception ex) { - while (Monitor.IsEntered(LayoutMutex)) + while (Monitor.IsEntered(LayoutMutex)) { + Console.WriteLine ($"[DebugIFace] trying to exit LayoutMutex on error"); + Monitor.Exit (LayoutMutex); + } + while (Monitor.IsEntered(UpdateMutex)) { + Console.WriteLine ($"[DebugIFace] trying to exit UpdateMutex on error"); + Monitor.Exit (UpdateMutex); + } + while (Monitor.IsEntered(ClippingMutex)) { + Console.WriteLine ($"[DebugIFace] trying to exit ClippingMutex on error"); + Monitor.Exit (ClippingMutex); + } + + + /*while (Monitor.IsEntered(LayoutMutex)) Monitor.Exit (LayoutMutex); while (Monitor.IsEntered(UpdateMutex)) Monitor.Exit (UpdateMutex); while (Monitor.IsEntered(ClippingMutex)) - Monitor.Exit (ClippingMutex); - delSetCurrentException (ex); + Monitor.Exit (ClippingMutex);*/ + delSetCurrentException (ex); + Console.WriteLine ($"[DbgIFace] {ex}"); ClearInterface(); Thread.Sleep(1000); } diff --git a/Samples/DebugLogAnalyzer/src/Program.cs b/Samples/DebugLogAnalyzer/src/Program.cs index 8cee874a..13e0234d 100644 --- a/Samples/DebugLogAnalyzer/src/Program.cs +++ b/Samples/DebugLogAnalyzer/src/Program.cs @@ -21,8 +21,7 @@ namespace DebugLogAnalyzer static void Main (string [] args) { - DbgLogger.IncludeEvents = DbgEvtType.None; - DbgLogger.DiscardEvents = DbgEvtType.All; + initDebugLog (); using (Program app = new Program ()) { CurrentProgramInstance = app; @@ -195,15 +194,6 @@ namespace DebugLogAnalyzer } public List CurWidgetRootEvents => curWidget == null? new List() : curWidget.RootEvents; - public bool DebugLogToFile { - get => Configuration.Global.Get (nameof(DebugLogToFile)); - set { - if (DbgLogger.ConsoleOutput != value) - return; - Configuration.Global.Set (nameof(DebugLogToFile), value); - NotifyValueChanged(DebugLogToFile); - } - } /*public string DebugLogFilePath { get => Configuration.Global.Get (nameof (DebugLogFilePath)); set { @@ -216,8 +206,8 @@ namespace DebugLogAnalyzer public bool DebugLogOnStartup { get => Configuration.Global.Get (nameof(DebugLogOnStartup)); set { - if (DbgLogger.ConsoleOutput != value) - return; + if (DebugLogOnStartup == value) + return; Configuration.Global.Set (nameof(DebugLogOnStartup), value); NotifyValueChanged(DebugLogOnStartup); } diff --git a/Samples/DebugLogAnalyzer/ui/DebugLog.crow b/Samples/DebugLogAnalyzer/ui/DebugLog.crow index 2b5ab978..a4e947af 100644 --- a/Samples/DebugLogAnalyzer/ui/DebugLog.crow +++ b/Samples/DebugLogAnalyzer/ui/DebugLog.crow @@ -31,7 +31,7 @@