Skip to content

Commit e1f8a98

Browse files
Fix: Prevent exceptions when available size is zero or negative
1 parent 1d81df8 commit e1f8a98

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/Files.App.Controls/BreadcrumbBar/BreadcrumbBarLayout.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,21 @@ protected override Size MeasureOverride(NonVirtualizingLayoutContext context, Si
3333
var accumulatedSize = new Size(0, 0);
3434
_availableSize = availableSize;
3535

36+
// Ensure we have a minimum size to prevent DivideByZeroException in WinUI
37+
// When availableSize has zero dimensions, provide a minimal positive size for measurement
38+
var measureSize = new Size(
39+
Math.Max(availableSize.Width, 1.0),
40+
Math.Max(availableSize.Height, 1.0)
41+
);
42+
3643
var indexAfterEllipsis = GetFirstIndexToRender(context);
3744

3845
// Go through all items and measure them
3946
for (int index = 0; index < context.Children.Count; index++)
4047
{
4148
if (context.Children[index] is BreadcrumbBarItem breadcrumbItem)
4249
{
43-
breadcrumbItem.Measure(availableSize);
50+
breadcrumbItem.Measure(measureSize);
4451
accumulatedSize.Width += index < indexAfterEllipsis ? 0 : breadcrumbItem.DesiredSize.Width;
4552
accumulatedSize.Height = Math.Max(accumulatedSize.Height, breadcrumbItem.DesiredSize.Height);
4653
}
@@ -98,6 +105,10 @@ private int GetFirstIndexToRender(NonVirtualizingLayoutContext context)
98105
var itemCount = context.Children.Count;
99106
var accumulatedWidth = 0d;
100107

108+
// Handle zero or negative available width - hide all items
109+
if (_availableSize.Width <= 0)
110+
return itemCount;
111+
101112
// Go through all items from the last item
102113
for (int index = itemCount - 1; index >= 0; index--)
103114
{

0 commit comments

Comments
 (0)