Skip to content

Commit ee24994

Browse files
committed
Fix AG_E_LAYOUT_CYCLE crash in widgets due to MinHeight exceeding MaxHeight
When rendering adaptive cards in widgets with fixed dimensions, setting a MinHeight value greater than the MaxHeight constraint caused XAML to throw AG_E_LAYOUT_CYCLE (0x802B0014), resulting in widget crashes. Changes: - XamlBuilder.cpp: Clamp card MinHeight to not exceed fixed height when fixedDimensions are set, preventing impossible layout constraints - AdaptiveCarouselRenderer.cpp: Apply same constraint validation for carousel elements with HeightInPixels property The fix ensures MinHeight never exceeds MaxHeight by automatically clamping the value to the maximum allowed height, allowing cards to render successfully without layout cycle errors.
1 parent 368bb76 commit ee24994

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

source/uwp/SharedRenderer/lib/AdaptiveCarouselRenderer.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,21 @@ namespace winrt::AdaptiveCards::Rendering::Xaml_Rendering::implementation
9595
}
9696

9797
uint32_t carouselMinHeight = styledCollection.MinHeight();
98+
auto fixedHeightInPixel = carousel.HeightInPixels();
9899

100+
// Ensure MinHeight doesn't exceed fixed height to prevent AG_E_LAYOUT_CYCLE
99101
if (carouselMinHeight > 0)
100102
{
101-
gridContainer.MinHeight(carouselMinHeight);
103+
if (fixedHeightInPixel && carouselMinHeight > fixedHeightInPixel)
104+
{
105+
gridContainer.MinHeight(static_cast<double>(fixedHeightInPixel));
106+
}
107+
else
108+
{
109+
gridContainer.MinHeight(carouselMinHeight);
110+
}
102111
}
103112

104-
auto fixedHeightInPixel = carousel.HeightInPixels();
105113
if (fixedHeightInPixel)
106114
{
107115
carouselUI.MaxHeight(static_cast<double>(fixedHeightInPixel));

source/uwp/SharedRenderer/lib/XamlBuilder.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,16 @@ namespace AdaptiveCards::Rendering::Xaml_Rendering
6262

6363
if (cardMinHeight > 0)
6464
{
65-
rootAsFrameworkElement.MinHeight(cardMinHeight);
65+
// If fixed dimensions are set, ensure MinHeight doesn't exceed MaxHeight to prevent AG_E_LAYOUT_CYCLE
66+
if (xamlBuilder && xamlBuilder->m_fixedDimensions && cardMinHeight > xamlBuilder->m_fixedHeight)
67+
{
68+
// Clamp MinHeight to not exceed the fixed height constraint
69+
rootAsFrameworkElement.MinHeight(xamlBuilder->m_fixedHeight);
70+
}
71+
else
72+
{
73+
rootAsFrameworkElement.MinHeight(cardMinHeight);
74+
}
6675
}
6776

6877
auto selectAction = adaptiveCard.SelectAction();

0 commit comments

Comments
 (0)