Răsfoiți Sursa

Increase max number of permitted layout attempts.

And log a message when a control was skipped due to a layout cycle.
Steven Kirk 2 ani în urmă
părinte
comite
109c05aeab

+ 1 - 1
src/Avalonia.Base/Layout/LayoutManager.cs

@@ -17,7 +17,7 @@ namespace Avalonia.Layout
     /// </summary>
     public class LayoutManager : ILayoutManager, IDisposable
     {
-        private const int MaxPasses = 3;
+        private const int MaxPasses = 10;
         private readonly Layoutable _owner;
         private readonly LayoutQueue<Layoutable> _toMeasure = new LayoutQueue<Layoutable>(v => !v.IsMeasureValid);
         private readonly LayoutQueue<Layoutable> _toArrange = new LayoutQueue<Layoutable>(v => !v.IsArrangeValid);

+ 15 - 3
src/Avalonia.Base/Layout/LayoutQueue.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Collections;
 using System.Collections.Generic;
+using Avalonia.Logging;
 
 namespace Avalonia.Layout
 {
@@ -48,10 +49,21 @@ namespace Avalonia.Layout
         {
             _loopQueueInfo.TryGetValue(item, out var info);
 
-            if (!info.Active && info.Count < _maxEnqueueCountPerLoop)
+            if (!info.Active)
             {
-                _inner.Enqueue(item);
-                _loopQueueInfo[item] = new Info() { Active = true, Count = info.Count + 1 };
+                if (info.Count < _maxEnqueueCountPerLoop)
+                {
+                    _inner.Enqueue(item);
+                    _loopQueueInfo[item] = new Info() { Active = true, Count = info.Count + 1 };
+                }
+                else
+                {
+                    Logger.TryGet(LogEventLevel.Warning, LogArea.Layout)?.Log(
+                        this,
+                        "Layout cycle detected. Item {Item} was enqueued {Count} times.",
+                        item,
+                        info.Count);
+                }
             }
         }