Skip to content

[Windows]Fix: Label Formatted Text crashed with out of memory Exception - #36828

Merged
kubaflo merged 1 commit into
dotnet:inflight/currentfrom
SubhikshaSf4851:Fix-35527
Aug 1, 2026
Merged

kubaflo merged 1 commit into
dotnet:inflight/currentfrom
SubhikshaSf4851:Fix-35527

Conversation

@SubhikshaSf4851

Copy link
Copy Markdown
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment whether this change resolves your issue. Thank you!

This pull request addresses a critical bug where showing a Label with formatted text after it has been hidden could cause the UI thread to hang and eventually crash with an OutOfMemoryException. The fix introduces a guard against zero or negative line heights in the RecalculateSpanPositions method. Additionally, a new test is added to ensure this scenario is handled correctly.

Description of Change:

Bug fix for line height calculation:

  • Added a guard in RecalculateSpanPositions (in FormattedStringExtensions.cs) to break out of the loop if a zero or negative line height is encountered, preventing infinite loops and memory issues when a TextBlock is measured while collapsed or hidden.

Testing improvements:

  • Added a test (FormattedTextDoesNotHangOrCrashWhenLabelIsShownAfterBeingSetWhileHidden) in LabelTests.Windows.cs to verify that showing a previously hidden label with formatted text does not hang or crash the UI.
  • Added necessary using directives for Microsoft.Maui.Controls and Xunit to support the new test.

Issues Fixed

Fixes #35527

Tested the behavior in the following platforms

  • Windows
  • Android
  • iOS
  • Mac
Before Issue Fix After Issue Fix
BeforeFix35527 AfterFix35527

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 36828

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 36828"

@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label Jul 27, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hey there @@SubhikshaSf4851! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@dotnet-policy-service dotnet-policy-service Bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Jul 27, 2026
@SubhikshaSf4851 SubhikshaSf4851 changed the title [WIP][Windows]Fix: Label Formatted Text crashed with out of memory Exception [Windows]Fix: Label Formatted Text crashed with out of memory Exception Jul 28, 2026
@vishnumenon2684

Copy link
Copy Markdown
Contributor

/azp run maui-pr-uitests , maui-pr-devicetests

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).

@kubaflo kubaflo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this one ready for review?

@sheiksyedm
sheiksyedm marked this pull request as ready for review July 31, 2026 05:34
Copilot AI review requested due to automatic review settings July 31, 2026 05:34
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a Windows-specific Label.FormattedText crash/hang caused by an infinite loop in FormattedStringExtensions.RecalculateSpanPositions when cached MeasuredLineHeight is 0 after measuring while hidden/collapsed. It also adds a Windows device test to cover the “set formatted text while hidden, then show” scenario.

Changes:

  • Add a guard in RecalculateSpanPositions to avoid infinite growth of lineHeights when computed line height is <= 0.
  • Add a Windows device test which sets FormattedText while IsVisible=false and then shows the label to ensure no hang/crash occurs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Controls/src/Core/Platform/Windows/Extensions/FormattedStringExtensions.cs Adds a safety guard to prevent infinite looping/OOM during span region calculation when line height is invalid.
src/Controls/tests/DeviceTests/Elements/Label/LabelTests.Windows.cs Adds a Windows device test to validate that showing a hidden label with formatted text does not hang/crash.

Comment thread src/Controls/tests/DeviceTests/Elements/Label/LabelTests.Windows.cs
@kubaflo

kubaflo commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

/review -b improved-reviewer -p catalyst

kubaflo pushed a commit that referenced this pull request Jul 31, 2026
…drops a /review

The trigger-review job did a FULL clone of the large dotnet/maui repo with only the
job's 10-min timeout to stop it. A transient network stall on that clone made the
"Checkout repository scripts" step hang until the JOB timeout CANCELLED the whole job —
silently, because a cancellation skips the downstream steps (no pipeline queued, no
notice). Observed repeatedly: #35640, and #36828 (trigger run 30647459829 cancelled at
"Checkout repository scripts").

- Shallow the checkout (fetch-depth: 1) — this job only needs .github/scripts, so it now
  completes in seconds instead of cloning full history.
- Add a per-step timeout-minutes: 4 (< the job's 10) so a rare stall becomes a proper
  step FAILURE that runs the cleanup/notice steps, instead of a job-level cancellation.
- Add a cancelled()/failure() notice step that posts a "transient infra — re-comment
  /review" warning using gh + the event payload directly (no repo scripts, which may be
  exactly what failed to check out), so a checkout hang is never silent again.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 15d2af20-e4ab-4e88-9011-cfbd83513bc0
@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Jul 31, 2026
@MauiBot MauiBot added s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates labels Jul 31, 2026
@MauiBot MauiBot added the s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review) label Jul 31, 2026
@MauiBot

This comment has been minimized.

@MauiBot MauiBot removed the s/agent-review-in-progress AI review is currently running for this PR label Jul 31, 2026
kubaflo pushed a commit that referenced this pull request Aug 1, 2026
…drops a /review

The trigger-review job did a FULL clone of the large dotnet/maui repo with only the
job's 10-min timeout to stop it. A transient network stall on that clone made the
"Checkout repository scripts" step hang until the JOB timeout CANCELLED the whole job —
silently, because a cancellation skips the downstream steps (no pipeline queued, no
notice). Observed repeatedly: #35640, and #36828 (trigger run 30647459829 cancelled at
"Checkout repository scripts").

- Shallow the checkout (fetch-depth: 1) — this job only needs .github/scripts, so it now
  completes in seconds instead of cloning full history.
- Add a per-step timeout-minutes: 4 (< the job's 10) so a rare stall becomes a proper
  step FAILURE that runs the cleanup/notice steps, instead of a job-level cancellation.
- Add a cancelled()/failure() notice step that posts a "transient infra — re-comment
  /review" warning using gh + the event payload directly (no repo scripts, which may be
  exactly what failed to check out), so a checkout hang is never silent again.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 15d2af20-e4ab-4e88-9011-cfbd83513bc0
@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Aug 1, 2026
@MauiBot

MauiBot commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

AI Review Summary

@SubhikshaSf4851 — new AI review results are available based on this last commit: e39f983.

Gate Inconclusive Confidence Low Platform Windows


🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix

Gate Result: ⚠️ INCONCLUSIVE

Platform: WINDOWS · Base: main · Merge base: b84104ac

🩺 Could not verify — environment/infrastructure error. The gate ran the tests but hit an environment error (the test app crashed or exited before writing its results, an emulator/simulator/Appium/XHarness flake, or an empty/invalid result file), so it could not record a real pass/fail. The ⚠️ ENV ERROR marks below are infrastructure, not test failures — this is not a problem with your PR. Comment /review to retry on a fresh agent.

Windows device test result file 'artifacts\log\TestResults-Microsoft_Maui_Controls_DeviceTests_Label.xml' is empty or not valid XML (the device-test app likely crashed or exited before writing results).

Test Without Fix (expect FAIL) With Fix (expect PASS)
📱 LabelTests (FormattedTextDoesNotHangOrCrashWhenLabelIsShownAfterBeingSetWhileHidden) Category=Label ⚠️ ENV ERROR ⚠️ ENV ERROR
🔴 Without fix — 📱 LabelTests (FormattedTextDoesNotHangOrCrashWhenLabelIsShownAfterBeingSetWhileHidden): ⚠️ ENV ERROR · 325s

No log file found

🟢 With fix — 📱 LabelTests (FormattedTextDoesNotHangOrCrashWhenLabelIsShownAfterBeingSetWhileHidden): ⚠️ ENV ERROR · 185s

No log file found

⚠️ Failure Details

  • ⚠️ LabelTests (FormattedTextDoesNotHangOrCrashWhenLabelIsShownAfterBeingSetWhileHidden) without fix: Windows device test result file 'artifacts\log\TestResults-Microsoft_Maui_Controls_DeviceTests_Label.xml' is empty or not valid XML (the device-test app likely crashed or exited before writing results).
  • ⚠️ LabelTests (FormattedTextDoesNotHangOrCrashWhenLabelIsShownAfterBeingSetWhileHidden) with fix: Windows device test result file 'artifacts\log\TestResults-Microsoft_Maui_Controls_DeviceTests_Label.xml' is empty or not valid XML (the device-test app likely crashed or exited before writing results).
📁 Fix files reverted (1 files)
  • src/Controls/src/Core/Platform/Windows/Extensions/FormattedStringExtensions.cs

📱 UI Tests — Label

Detected UI test categories: Label

✅ Deep UI tests — 91 passed, 0 failed across 1 category on platform-pool agent (replaces in-process counts above).

🧪 UI Test Execution Results (deep, platform pool)

Category Tests Snapshot diffs
Label 91/94 ✓ —
📎 Download drop-deep-uitests artifact (TRX + snapshot diffs)

📋 Pre-Flight — Context & Validation

Issue: #35527 - Label with FormattedText crashes with OutOfMemoryException in RecalculateSpanPositions on Windows when text exceeds ~150 characters
PR: #36828 - [Windows]Fix: Label Formatted Text crashed with out of memory Exception
Platforms Affected: Windows
Files Changed: 1 implementation, 1 test

Key Findings

  • Windows Label.FormattedText can hang/OOM in FormattedStringExtensions.RecalculateSpanPositions when a hidden/collapsed TextBlock caches MeasuredLineHeight == 0 and later recalculates wrapped span positions.
  • PR fix adds a lineHeight <= 0 break, which stops the infinite loop but can leave partial lineHeights and assign an incomplete Region for wrapped spans.
  • Existing regression test verifies no hang/crash but does not verify span region/hit-test correctness after the label is shown.
  • Prior inline feedback raised the same partial-region risk; author replied that no change was needed, and the current diff still contains the break path.

Code Review Summary

Verdict: NEEDS_CHANGES
Confidence: low
Errors: 1 | Warnings: 1 | Suggestions: 0

Key code review findings:

  • ✗ src/Controls/src/Core/Platform/Windows/Extensions/FormattedStringExtensions.cs:238 — break can truncate multi-line span hit-test regions by preserving a partial lineHeights list and still assigning Region.FromLines(...).
  • ⚠ src/Controls/tests/DeviceTests/Elements/Label/LabelTests.Windows.cs:79 — test proves no hang but not that span regions remain correct.

Fix Candidates

# Source Approach Test Result Files Changed Notes
PR PR #36828 Break out of line-height accumulation when a computed line height is <= 0. ⚠️ INCONCLUSIVE (Gate) src/Controls/src/Core/Platform/Windows/Extensions/FormattedStringExtensions.cs, src/Controls/tests/DeviceTests/Elements/Label/LabelTests.Windows.cs Original PR; prevents OOM but may leave incomplete span regions.

🔬 Code Review — Deep Analysis

Code Review — PR #36828

Independent Assessment

What this changes: Adds a Windows Label.FormattedText span-position guard that breaks out of line-height accumulation when computed line height is <= 0, plus a Windows device test for showing a hidden formatted label.
Inferred motivation: Avoid an infinite loop/OOM when MeasuredLineHeight was cached as 0 while the TextBlock was hidden/collapsed.

Reconciliation with PR Narrative

Author claims: Fixes Windows OOM/hang for hidden/long formatted labels and adds coverage.
Agreement/disagreement: The guard prevents the infinite loop, but it can still assign an incomplete span region, so the fix is not complete for interactive formatted spans.

Prior Review Reconciliation

Prior ❌ Error Finding Source Status Evidence
break can leave lineHeights incomplete and produce undersized hit-test regions for multi-line spans. Copilot inline review / MauiBot summary ❌ Unresolved Current code still breaks at FormattedStringExtensions.cs:238-240 and still calls Region.FromLines(lineHeights...) at lines 247-253 with the partial list. Author replied “No changes needed,” but no code changed.

Blast Radius Assessment

  • Runs for all instances: Yes — every Windows formatted Label recalculates span regions during arrange.
  • Startup impact: No direct startup impact; runs during layout/arrange.
  • Static/shared state: No new static state.
  • Platform/UI plumbing: Yes — Windows text/span hit-testing layout.

CI Status

  • Required-check result: undetermined — gh pr checks 36828 --repo dotnet/maui --required failed because GitHub CLI is unauthenticated.
  • Classification: undetermined. Public check-runs on the head SHA also show Build Analysis and maui-pr-uitests failures/in-progress, while maui-pr passed.
  • Action taken: confidence capped low.

Findings

❌ Error — Guard can truncate multi-line span hit-test regions

src/Controls/src/Core/Platform/Windows/Extensions/FormattedStringExtensions.cs:238

The new guard stops the infinite loop, but break preserves any partial lineHeights collected and still assigns that partial region to the span. If a hidden formatted label caches MeasuredLineHeight = 0, then after showing, a wrapped span can record only the first visual line, break on the middle-line branch, and create a single-line Region. Taps/gestures on later wrapped lines can miss.

⚠️ Warning — Regression test only proves no hang

src/Controls/tests/DeviceTests/Elements/Label/LabelTests.Windows.cs:79

The test waits for completion but does not assert that span regions remain correct after showing the label. This allows the partial-region regression above to pass.

External Output Contract

Consumer token/pattern Producer location Producer emission condition Consumer assumption Ordinary negative case Downstream effect
N/A N/A No changed code classifies external tool output. N/A N/A N/A

Failure-Mode Probing

  • Hidden multi-line span with tap recognizer: no OOM, but later wrapped lines can be outside the assigned Region.
  • Non-interactive formatted text: rendering may look fine, masking the hit-test regression.
  • Handler/layout reconnect: arrange recalculates, but stale MeasuredLineHeight == 0 repeats the truncated-region path.

Verdict: NEEDS_CHANGES

Confidence: low (Windows platform UI plumbing plus CI status undetermined; confidence in the specific defect is high.)
Summary: The PR addresses the OOM symptom but leaves a concrete correctness bug for wrapped formatted spans with gestures. The unresolved prior ❌ finding also requires NEEDS_CHANGES.


🛠️ Fix — Analysis & Comparison

Fix Candidates

# Source Approach Test Result Files Changed Notes
1 try-fix-1 Substitute a positive fallback line height inside RecalculateSpanPositions instead of breaking when cached/middle line height is non-positive. ⚠️ Blocked 1 file Build succeeded; Windows device-test result parser crashed. Preserves wrapped span regions better than PR, but still handles poisoned cache in the arrange loop.
2 try-fix-2 Prevent FindDefaultLineHeight from caching zero by returning a positive font-metric fallback for hidden/collapsed TextBlocks; remove PR's arrange-time break. ⚠️ Blocked 2 files Build succeeded and Label category did not hang; result parser crashed. Strongest candidate: root-cause fix, complete regions, fewer arrange-loop branches.
3 try-fix-3 On invalid line geometry, build conservative fallback rectangles instead of calling Region.FromLines with partial line heights. ⚠️ Blocked 1 file Build succeeded; result parser crashed. Self-review found moderate over-match risk for multiple gesture spans.
4 try-fix-4 Skip region update when line geometry is invalid so partial data is not published. ⚠️ Blocked 1 file Build succeeded; result parser crashed. Self-review found moderate stale/default region risk for span hit-testing.
PR PR #36828 Break out of line-height accumulation when computed line height is <= 0. ⚠️ INCONCLUSIVE (Gate) 2 files Original PR prevents OOM but can assign partial span regions.

Cross-Pollination

Model Round New Ideas? Details
claude-opus-4.6 1 Yes Positive fallback line-height strategy (implemented as try-fix-1).
claude-opus-4.7 1 Yes Fix zero cached default line height at FindDefaultLineHeight (implemented as try-fix-2).
gpt-5.3-codex 1 Yes Conservative fallback region on invalid geometry (implemented as try-fix-3); moderate over-match risk found.
gpt-5.5 1 Yes Geometry deferral/no partial region update (implemented as try-fix-4); moderate stale/default region risk found.
claude-opus-4.6 2 Yes One-shot LayoutUpdated/dispatcher retry after valid layout. Not run: a retry alone still reuses the poisoned zero MeasuredLineHeight cache, so it degenerates into stale/no region or repeated retries unless combined with try-fix-2's cache fix.
claude-opus-4.7 2 Yes Replace inferred line-height accumulation with authoritative TextLayout/TextLine metrics. Not run: WinUI TextBlock does not expose a simple per-line text layout API in this call path; implementing a parallel text layout engine would be a broad refactor, not a focused candidate.
gpt-5.3-codex 2 No Remaining ideas are trivial recombinations of symptom guards or the cache fix.
gpt-5.5 2 Yes Defer region recomputation until visible layout and clear/preserve no region while hidden. Not run separately because this is the same family as try-fix-4 plus the same poisoned-cache limitation as the layout retry idea.

Exhausted: Yes
Selected Fix: Candidate #2 (try-fix-2) — best blocked candidate. It fixes the zero line-height cache at the source, removes the PR's partial-region break, preserves complete multi-line span regions, and avoids adding work to the arrange hot path. It could not be declared passing because the Windows device-test result parser failed after execution, the same environment blocker seen across all candidates.


📝 Recommended PR Title & Description

Assessment: ✏️ Recommend updating — the current metadata accurately describes the raw PR, but the winning fix moves the core guard from RecalculateSpanPositions to FindDefaultLineHeight, so the title/description should describe the root-cause cache fix and preserved span regions.

Recommended title

[Windows] Label: Prevent zero formatted-text line heights while hidden

Recommended description

This pull request addresses a critical Windows bug where showing a `Label` with formatted text after it has been hidden could cause the UI thread to hang and eventually crash with an `OutOfMemoryException`.

### Description of Change:
**Bug fix for line height calculation:**

* Prevents `TextBlockExtensions.FindDefaultLineHeight` from caching a zero or negative `MeasuredLineHeight` when a `TextBlock` is measured while hidden/collapsed.
* Falls back to a positive font-size-based line-height estimate when WinUI measurement returns `DesiredSize.Height <= 0`, so `FormattedStringExtensions.RecalculateSpanPositions` can continue producing complete wrapped span regions.
* Avoids the downstream partial-region behavior caused by breaking out of `RecalculateSpanPositions` after only some line heights have been collected.

**Testing improvements:**

* Added a Windows device test (`FormattedTextDoesNotHangOrCrashWhenLabelIsShownAfterBeingSetWhileHidden`) in `LabelTests.Windows.cs` to verify that showing a previously hidden label with formatted text does not hang or crash the UI.
* Added necessary `using` directives for `Microsoft.Maui.Controls` and `Xunit` to support the new test.

### Issues Fixed

Fixes #35527

### Tested the behavior in the following platforms

- [x] Windows
- [ ] Android
- [ ] iOS
- [ ] Mac

| Before Issue Fix | After Issue Fix |
|----------|----------|
| <img width="1404" height="560" alt="BeforeFix35527" src="https://github.com/user-attachments/assets/5701a105-c57f-4f84-be87-2e1eacfa97d1" /> | <img width="1417" height="732" alt="AfterFix35527" src="https://github.com/user-attachments/assets/f85350ef-43bb-47a6-8273-eb3446b81c95" /> |

🏁 Report — Final Recommendation

Comparative Candidate Report — PR #36828

Summary

Winning candidate: pr-plus-reviewer

The raw PR fix prevents the OOM/hang, but it can still publish incomplete span regions after breaking out of line-height reconstruction. pr-plus-reviewer applies the expert review feedback using the same root-cause strategy as try-fix-2: prevent zero line-height cache population in FindDefaultLineHeight, then remove the partial-region break from RecalculateSpanPositions. No candidate had a passing regression-test result; all executable attempts were blocked/inconclusive by Windows device-test infrastructure/result parsing, so ranking is based on code correctness and available build/hang evidence rather than a pass/fail result.

Candidate ranking

Rank Candidate Test result Assessment
1 pr-plus-reviewer ⚠️ Inconclusive / sandbox-applied Best overall. Applies expert feedback to the PR by fixing the non-positive cached line height at source and preserving complete span-region geometry. Equivalent correctness profile to try-fix-2, but named as the reviewer-applied PR candidate.
2 try-fix-2 ⚠️ Blocked Strongest independent try-fix. Build succeeded, the Label category did not hang, and it fixes the root cause in FindDefaultLineHeight. Ranked just below pr-plus-reviewer only because pr-plus-reviewer adopts the same approach as the PR-reviewer-applied candidate.
3 try-fix-1 ⚠️ Blocked Better than raw PR because it substitutes a positive fallback and avoids immediate partial geometry, but it still tolerates a poisoned cached MeasuredLineHeight and patches the arrange loop instead of the source.
4 try-fix-3 ⚠️ Blocked Avoids partial Region.FromLines(...), but the conservative rectangle fallback can over-match hit-testing for multiple gesture spans.
5 try-fix-4 ⚠️ Blocked Avoids publishing partial geometry, but can leave stale/default regions and disable hit-testing if the zero cache is never repopulated.
6 pr ⚠️ Inconclusive gate Prevents the infinite loop/OOM, but unresolved review finding remains: break can truncate line geometry and publish an incomplete span region.

Regression-test rule

No candidate had a confirmed passing regression-test result. The raw PR gate was inconclusive because Windows device-test result XML was empty/invalid, and all STEP 5a try-fix candidates were blocked by the Windows device-test result parser after builds completed. None of the candidates are treated as failing, but none receives a pass advantage.

Why pr-plus-reviewer wins

The issue root cause is a zero MeasuredLineHeight cached while the TextBlock is hidden/collapsed. The raw PR breaks the downstream reconstruction loop when that zero appears, which avoids the unbounded loop but leaves downstream region assignment with partial data. The reviewer-applied candidate fixes the cache before RecalculateSpanPositions observes it, which makes the loop terminate normally and preserves wrapped span regions.

Recommended action

Adopt the pr-plus-reviewer implementation: move the guard/fallback to TextBlockExtensions.FindDefaultLineHeight, remove the lineHeight <= 0 break from FormattedStringExtensions.RecalculateSpanPositions, and keep the Windows no-hang regression test. If time permits, add a follow-up assertion/test for span-region or gesture hit-testing across wrapped formatted text, because the current test only proves the UI thread does not hang.


🧭 Next Steps — review latest findings

No alternative fix was selected for this run. Review the session findings and CI results before merging.

@MauiBot MauiBot removed the s/agent-review-in-progress AI review is currently running for this PR label Aug 1, 2026
@kubaflo
kubaflo changed the base branch from main to inflight/current August 1, 2026 18:09
@kubaflo
kubaflo merged commit 22e1306 into dotnet:inflight/current Aug 1, 2026
86 of 100 checks passed
@github-actions github-actions Bot added this to the .NET 10 SR10 milestone Aug 1, 2026
kubaflo pushed a commit that referenced this pull request Aug 7, 2026
…on (#36828)

<!-- Please keep the note below for people who find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment whether this change resolves your
issue. Thank you!

This pull request addresses a critical bug where showing a `Label` with
formatted text after it has been hidden could cause the UI thread to
hang and eventually crash with an `OutOfMemoryException`. The fix
introduces a guard against zero or negative line heights in the
`RecalculateSpanPositions` method. Additionally, a new test is added to
ensure this scenario is handled correctly.

### Description of Change:
**Bug fix for line height calculation:**

* Added a guard in `RecalculateSpanPositions` (in
`FormattedStringExtensions.cs`) to break out of the loop if a zero or
negative line height is encountered, preventing infinite loops and
memory issues when a `TextBlock` is measured while collapsed or hidden.

**Testing improvements:**

* Added a test
(`FormattedTextDoesNotHangOrCrashWhenLabelIsShownAfterBeingSetWhileHidden`)
in `LabelTests.Windows.cs` to verify that showing a previously hidden
label with formatted text does not hang or crash the UI.
* Added necessary `using` directives for `Microsoft.Maui.Controls` and
`Xunit` to support the new test.


<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #35527 

### Tested the behavior in the following platforms

- [x] Windows
- [ ] Android
- [ ] iOS
- [ ] Mac

| Before Issue Fix | After Issue Fix |
|----------|----------|
| <img width="1404" height="560" alt="BeforeFix35527"
src="https://github.com/user-attachments/assets/5701a105-c57f-4f84-be87-2e1eacfa97d1"
/> | <img width="1417" height="732" alt="AfterFix35527"
src="https://github.com/user-attachments/assets/f85350ef-43bb-47a6-8273-eb3446b81c95"
/> |
<!--
<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Aug 12, 2026
…on (#36828)

<!-- Please keep the note below for people who find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment whether this change resolves your
issue. Thank you!

This pull request addresses a critical bug where showing a `Label` with
formatted text after it has been hidden could cause the UI thread to
hang and eventually crash with an `OutOfMemoryException`. The fix
introduces a guard against zero or negative line heights in the
`RecalculateSpanPositions` method. Additionally, a new test is added to
ensure this scenario is handled correctly.

### Description of Change:
**Bug fix for line height calculation:**

* Added a guard in `RecalculateSpanPositions` (in
`FormattedStringExtensions.cs`) to break out of the loop if a zero or
negative line height is encountered, preventing infinite loops and
memory issues when a `TextBlock` is measured while collapsed or hidden.

**Testing improvements:**

* Added a test
(`FormattedTextDoesNotHangOrCrashWhenLabelIsShownAfterBeingSetWhileHidden`)
in `LabelTests.Windows.cs` to verify that showing a previously hidden
label with formatted text does not hang or crash the UI.
* Added necessary `using` directives for `Microsoft.Maui.Controls` and
`Xunit` to support the new test.


<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #35527 

### Tested the behavior in the following platforms

- [x] Windows
- [ ] Android
- [ ] iOS
- [ ] Mac

| Before Issue Fix | After Issue Fix |
|----------|----------|
| <img width="1404" height="560" alt="BeforeFix35527"
src="https://github.com/user-attachments/assets/5701a105-c57f-4f84-be87-2e1eacfa97d1"
/> | <img width="1417" height="732" alt="AfterFix35527"
src="https://github.com/user-attachments/assets/f85350ef-43bb-47a6-8273-eb3446b81c95"
/> |
<!--
<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
@sheiksyedm sheiksyedm modified the milestones: .NET 10 SR10, .NET 10 SR11 Aug 26, 2026
kubaflo pushed a commit that referenced this pull request Aug 27, 2026
…on (#36828)

<!-- Please keep the note below for people who find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment whether this change resolves your
issue. Thank you!

This pull request addresses a critical bug where showing a `Label` with
formatted text after it has been hidden could cause the UI thread to
hang and eventually crash with an `OutOfMemoryException`. The fix
introduces a guard against zero or negative line heights in the
`RecalculateSpanPositions` method. Additionally, a new test is added to
ensure this scenario is handled correctly.

### Description of Change:
**Bug fix for line height calculation:**

* Added a guard in `RecalculateSpanPositions` (in
`FormattedStringExtensions.cs`) to break out of the loop if a zero or
negative line height is encountered, preventing infinite loops and
memory issues when a `TextBlock` is measured while collapsed or hidden.

**Testing improvements:**

* Added a test
(`FormattedTextDoesNotHangOrCrashWhenLabelIsShownAfterBeingSetWhileHidden`)
in `LabelTests.Windows.cs` to verify that showing a previously hidden
label with formatted text does not hang or crash the UI.
* Added necessary `using` directives for `Microsoft.Maui.Controls` and
`Xunit` to support the new test.


<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #35527 

### Tested the behavior in the following platforms

- [x] Windows
- [ ] Android
- [ ] iOS
- [ ] Mac

| Before Issue Fix | After Issue Fix |
|----------|----------|
| <img width="1404" height="560" alt="BeforeFix35527"
src="https://github.com/user-attachments/assets/5701a105-c57f-4f84-be87-2e1eacfa97d1"
/> | <img width="1417" height="732" alt="AfterFix35527"
src="https://github.com/user-attachments/assets/f85350ef-43bb-47a6-8273-eb3446b81c95"
/> |
<!--
<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Sep 2, 2026
…on (#36828)

<!-- Please keep the note below for people who find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment whether this change resolves your
issue. Thank you!

This pull request addresses a critical bug where showing a `Label` with
formatted text after it has been hidden could cause the UI thread to
hang and eventually crash with an `OutOfMemoryException`. The fix
introduces a guard against zero or negative line heights in the
`RecalculateSpanPositions` method. Additionally, a new test is added to
ensure this scenario is handled correctly.

### Description of Change:
**Bug fix for line height calculation:**

* Added a guard in `RecalculateSpanPositions` (in
`FormattedStringExtensions.cs`) to break out of the loop if a zero or
negative line height is encountered, preventing infinite loops and
memory issues when a `TextBlock` is measured while collapsed or hidden.

**Testing improvements:**

* Added a test
(`FormattedTextDoesNotHangOrCrashWhenLabelIsShownAfterBeingSetWhileHidden`)
in `LabelTests.Windows.cs` to verify that showing a previously hidden
label with formatted text does not hang or crash the UI.
* Added necessary `using` directives for `Microsoft.Maui.Controls` and
`Xunit` to support the new test.


<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #35527 

### Tested the behavior in the following platforms

- [x] Windows
- [ ] Android
- [ ] iOS
- [ ] Mac

| Before Issue Fix | After Issue Fix |
|----------|----------|
| <img width="1404" height="560" alt="BeforeFix35527"
src="https://github.com/user-attachments/assets/5701a105-c57f-4f84-be87-2e1eacfa97d1"
/> | <img width="1417" height="732" alt="AfterFix35527"
src="https://github.com/user-attachments/assets/f85350ef-43bb-47a6-8273-eb3446b81c95"
/> |
<!--
<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Sep 3, 2026
…on (#36828)

<!-- Please keep the note below for people who find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment whether this change resolves your
issue. Thank you!

This pull request addresses a critical bug where showing a `Label` with
formatted text after it has been hidden could cause the UI thread to
hang and eventually crash with an `OutOfMemoryException`. The fix
introduces a guard against zero or negative line heights in the
`RecalculateSpanPositions` method. Additionally, a new test is added to
ensure this scenario is handled correctly.

### Description of Change:
**Bug fix for line height calculation:**

* Added a guard in `RecalculateSpanPositions` (in
`FormattedStringExtensions.cs`) to break out of the loop if a zero or
negative line height is encountered, preventing infinite loops and
memory issues when a `TextBlock` is measured while collapsed or hidden.

**Testing improvements:**

* Added a test
(`FormattedTextDoesNotHangOrCrashWhenLabelIsShownAfterBeingSetWhileHidden`)
in `LabelTests.Windows.cs` to verify that showing a previously hidden
label with formatted text does not hang or crash the UI.
* Added necessary `using` directives for `Microsoft.Maui.Controls` and
`Xunit` to support the new test.


<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #35527 

### Tested the behavior in the following platforms

- [x] Windows
- [ ] Android
- [ ] iOS
- [ ] Mac

| Before Issue Fix | After Issue Fix |
|----------|----------|
| <img width="1404" height="560" alt="BeforeFix35527"
src="https://github.com/user-attachments/assets/5701a105-c57f-4f84-be87-2e1eacfa97d1"
/> | <img width="1417" height="732" alt="AfterFix35527"
src="https://github.com/user-attachments/assets/f85350ef-43bb-47a6-8273-eb3446b81c95"
/> |
<!--
<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Sep 3, 2026
…on (#36828)

<!-- Please keep the note below for people who find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment whether this change resolves your
issue. Thank you!

This pull request addresses a critical bug where showing a `Label` with
formatted text after it has been hidden could cause the UI thread to
hang and eventually crash with an `OutOfMemoryException`. The fix
introduces a guard against zero or negative line heights in the
`RecalculateSpanPositions` method. Additionally, a new test is added to
ensure this scenario is handled correctly.

### Description of Change:
**Bug fix for line height calculation:**

* Added a guard in `RecalculateSpanPositions` (in
`FormattedStringExtensions.cs`) to break out of the loop if a zero or
negative line height is encountered, preventing infinite loops and
memory issues when a `TextBlock` is measured while collapsed or hidden.

**Testing improvements:**

* Added a test
(`FormattedTextDoesNotHangOrCrashWhenLabelIsShownAfterBeingSetWhileHidden`)
in `LabelTests.Windows.cs` to verify that showing a previously hidden
label with formatted text does not hang or crash the UI.
* Added necessary `using` directives for `Microsoft.Maui.Controls` and
`Xunit` to support the new test.


<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #35527 

### Tested the behavior in the following platforms

- [x] Windows
- [ ] Android
- [ ] iOS
- [ ] Mac

| Before Issue Fix | After Issue Fix |
|----------|----------|
| <img width="1404" height="560" alt="BeforeFix35527"
src="https://github.com/user-attachments/assets/5701a105-c57f-4f84-be87-2e1eacfa97d1"
/> | <img width="1417" height="732" alt="AfterFix35527"
src="https://github.com/user-attachments/assets/f85350ef-43bb-47a6-8273-eb3446b81c95"
/> |
<!--
<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Sep 4, 2026
…on (#36828)

<!-- Please keep the note below for people who find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment whether this change resolves your
issue. Thank you!

This pull request addresses a critical bug where showing a `Label` with
formatted text after it has been hidden could cause the UI thread to
hang and eventually crash with an `OutOfMemoryException`. The fix
introduces a guard against zero or negative line heights in the
`RecalculateSpanPositions` method. Additionally, a new test is added to
ensure this scenario is handled correctly.

### Description of Change:
**Bug fix for line height calculation:**

* Added a guard in `RecalculateSpanPositions` (in
`FormattedStringExtensions.cs`) to break out of the loop if a zero or
negative line height is encountered, preventing infinite loops and
memory issues when a `TextBlock` is measured while collapsed or hidden.

**Testing improvements:**

* Added a test
(`FormattedTextDoesNotHangOrCrashWhenLabelIsShownAfterBeingSetWhileHidden`)
in `LabelTests.Windows.cs` to verify that showing a previously hidden
label with formatted text does not hang or crash the UI.
* Added necessary `using` directives for `Microsoft.Maui.Controls` and
`Xunit` to support the new test.


<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #35527 

### Tested the behavior in the following platforms

- [x] Windows
- [ ] Android
- [ ] iOS
- [ ] Mac

| Before Issue Fix | After Issue Fix |
|----------|----------|
| <img width="1404" height="560" alt="BeforeFix35527"
src="https://github.com/user-attachments/assets/5701a105-c57f-4f84-be87-2e1eacfa97d1"
/> | <img width="1417" height="732" alt="AfterFix35527"
src="https://github.com/user-attachments/assets/f85350ef-43bb-47a6-8273-eb3446b81c95"
/> |
<!--
<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Sep 6, 2026
…on (#36828)

<!-- Please keep the note below for people who find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment whether this change resolves your
issue. Thank you!

This pull request addresses a critical bug where showing a `Label` with
formatted text after it has been hidden could cause the UI thread to
hang and eventually crash with an `OutOfMemoryException`. The fix
introduces a guard against zero or negative line heights in the
`RecalculateSpanPositions` method. Additionally, a new test is added to
ensure this scenario is handled correctly.

### Description of Change:
**Bug fix for line height calculation:**

* Added a guard in `RecalculateSpanPositions` (in
`FormattedStringExtensions.cs`) to break out of the loop if a zero or
negative line height is encountered, preventing infinite loops and
memory issues when a `TextBlock` is measured while collapsed or hidden.

**Testing improvements:**

* Added a test
(`FormattedTextDoesNotHangOrCrashWhenLabelIsShownAfterBeingSetWhileHidden`)
in `LabelTests.Windows.cs` to verify that showing a previously hidden
label with formatted text does not hang or crash the UI.
* Added necessary `using` directives for `Microsoft.Maui.Controls` and
`Xunit` to support the new test.


<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #35527 

### Tested the behavior in the following platforms

- [x] Windows
- [ ] Android
- [ ] iOS
- [ ] Mac

| Before Issue Fix | After Issue Fix |
|----------|----------|
| <img width="1404" height="560" alt="BeforeFix35527"
src="https://github.com/user-attachments/assets/5701a105-c57f-4f84-be87-2e1eacfa97d1"
/> | <img width="1417" height="732" alt="AfterFix35527"
src="https://github.com/user-attachments/assets/f85350ef-43bb-47a6-8273-eb3446b81c95"
/> |
<!--
<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Sep 7, 2026
…on (#36828)

<!-- Please keep the note below for people who find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment whether this change resolves your
issue. Thank you!

This pull request addresses a critical bug where showing a `Label` with
formatted text after it has been hidden could cause the UI thread to
hang and eventually crash with an `OutOfMemoryException`. The fix
introduces a guard against zero or negative line heights in the
`RecalculateSpanPositions` method. Additionally, a new test is added to
ensure this scenario is handled correctly.

### Description of Change:
**Bug fix for line height calculation:**

* Added a guard in `RecalculateSpanPositions` (in
`FormattedStringExtensions.cs`) to break out of the loop if a zero or
negative line height is encountered, preventing infinite loops and
memory issues when a `TextBlock` is measured while collapsed or hidden.

**Testing improvements:**

* Added a test
(`FormattedTextDoesNotHangOrCrashWhenLabelIsShownAfterBeingSetWhileHidden`)
in `LabelTests.Windows.cs` to verify that showing a previously hidden
label with formatted text does not hang or crash the UI.
* Added necessary `using` directives for `Microsoft.Maui.Controls` and
`Xunit` to support the new test.


<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #35527 

### Tested the behavior in the following platforms

- [x] Windows
- [ ] Android
- [ ] iOS
- [ ] Mac

| Before Issue Fix | After Issue Fix |
|----------|----------|
| <img width="1404" height="560" alt="BeforeFix35527"
src="https://github.com/user-attachments/assets/5701a105-c57f-4f84-be87-2e1eacfa97d1"
/> | <img width="1417" height="732" alt="AfterFix35527"
src="https://github.com/user-attachments/assets/f85350ef-43bb-47a6-8273-eb3446b81c95"
/> |
<!--
<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Sep 7, 2026
…on (#36828)

<!-- Please keep the note below for people who find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment whether this change resolves your
issue. Thank you!

This pull request addresses a critical bug where showing a `Label` with
formatted text after it has been hidden could cause the UI thread to
hang and eventually crash with an `OutOfMemoryException`. The fix
introduces a guard against zero or negative line heights in the
`RecalculateSpanPositions` method. Additionally, a new test is added to
ensure this scenario is handled correctly.

### Description of Change:
**Bug fix for line height calculation:**

* Added a guard in `RecalculateSpanPositions` (in
`FormattedStringExtensions.cs`) to break out of the loop if a zero or
negative line height is encountered, preventing infinite loops and
memory issues when a `TextBlock` is measured while collapsed or hidden.

**Testing improvements:**

* Added a test
(`FormattedTextDoesNotHangOrCrashWhenLabelIsShownAfterBeingSetWhileHidden`)
in `LabelTests.Windows.cs` to verify that showing a previously hidden
label with formatted text does not hang or crash the UI.
* Added necessary `using` directives for `Microsoft.Maui.Controls` and
`Xunit` to support the new test.


<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #35527 

### Tested the behavior in the following platforms

- [x] Windows
- [ ] Android
- [ ] iOS
- [ ] Mac

| Before Issue Fix | After Issue Fix |
|----------|----------|
| <img width="1404" height="560" alt="BeforeFix35527"
src="https://github.com/user-attachments/assets/5701a105-c57f-4f84-be87-2e1eacfa97d1"
/> | <img width="1417" height="732" alt="AfterFix35527"
src="https://github.com/user-attachments/assets/f85350ef-43bb-47a6-8273-eb3446b81c95"
/> |
<!--
<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Sep 8, 2026
…on (#36828)

<!-- Please keep the note below for people who find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment whether this change resolves your
issue. Thank you!

This pull request addresses a critical bug where showing a `Label` with
formatted text after it has been hidden could cause the UI thread to
hang and eventually crash with an `OutOfMemoryException`. The fix
introduces a guard against zero or negative line heights in the
`RecalculateSpanPositions` method. Additionally, a new test is added to
ensure this scenario is handled correctly.

### Description of Change:
**Bug fix for line height calculation:**

* Added a guard in `RecalculateSpanPositions` (in
`FormattedStringExtensions.cs`) to break out of the loop if a zero or
negative line height is encountered, preventing infinite loops and
memory issues when a `TextBlock` is measured while collapsed or hidden.

**Testing improvements:**

* Added a test
(`FormattedTextDoesNotHangOrCrashWhenLabelIsShownAfterBeingSetWhileHidden`)
in `LabelTests.Windows.cs` to verify that showing a previously hidden
label with formatted text does not hang or crash the UI.
* Added necessary `using` directives for `Microsoft.Maui.Controls` and
`Xunit` to support the new test.


<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #35527 

### Tested the behavior in the following platforms

- [x] Windows
- [ ] Android
- [ ] iOS
- [ ] Mac

| Before Issue Fix | After Issue Fix |
|----------|----------|
| <img width="1404" height="560" alt="BeforeFix35527"
src="https://github.com/user-attachments/assets/5701a105-c57f-4f84-be87-2e1eacfa97d1"
/> | <img width="1417" height="732" alt="AfterFix35527"
src="https://github.com/user-attachments/assets/f85350ef-43bb-47a6-8273-eb3446b81c95"
/> |
<!--
<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Sep 8, 2026
…on (#36828)

<!-- Please keep the note below for people who find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment whether this change resolves your
issue. Thank you!

This pull request addresses a critical bug where showing a `Label` with
formatted text after it has been hidden could cause the UI thread to
hang and eventually crash with an `OutOfMemoryException`. The fix
introduces a guard against zero or negative line heights in the
`RecalculateSpanPositions` method. Additionally, a new test is added to
ensure this scenario is handled correctly.

### Description of Change:
**Bug fix for line height calculation:**

* Added a guard in `RecalculateSpanPositions` (in
`FormattedStringExtensions.cs`) to break out of the loop if a zero or
negative line height is encountered, preventing infinite loops and
memory issues when a `TextBlock` is measured while collapsed or hidden.

**Testing improvements:**

* Added a test
(`FormattedTextDoesNotHangOrCrashWhenLabelIsShownAfterBeingSetWhileHidden`)
in `LabelTests.Windows.cs` to verify that showing a previously hidden
label with formatted text does not hang or crash the UI.
* Added necessary `using` directives for `Microsoft.Maui.Controls` and
`Xunit` to support the new test.


<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #35527 

### Tested the behavior in the following platforms

- [x] Windows
- [ ] Android
- [ ] iOS
- [ ] Mac

| Before Issue Fix | After Issue Fix |
|----------|----------|
| <img width="1404" height="560" alt="BeforeFix35527"
src="https://github.com/user-attachments/assets/5701a105-c57f-4f84-be87-2e1eacfa97d1"
/> | <img width="1417" height="732" alt="AfterFix35527"
src="https://github.com/user-attachments/assets/f85350ef-43bb-47a6-8273-eb3446b81c95"
/> |
<!--
<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Sep 9, 2026
…on (#36828)

<!-- Please keep the note below for people who find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment whether this change resolves your
issue. Thank you!

This pull request addresses a critical bug where showing a `Label` with
formatted text after it has been hidden could cause the UI thread to
hang and eventually crash with an `OutOfMemoryException`. The fix
introduces a guard against zero or negative line heights in the
`RecalculateSpanPositions` method. Additionally, a new test is added to
ensure this scenario is handled correctly.

### Description of Change:
**Bug fix for line height calculation:**

* Added a guard in `RecalculateSpanPositions` (in
`FormattedStringExtensions.cs`) to break out of the loop if a zero or
negative line height is encountered, preventing infinite loops and
memory issues when a `TextBlock` is measured while collapsed or hidden.

**Testing improvements:**

* Added a test
(`FormattedTextDoesNotHangOrCrashWhenLabelIsShownAfterBeingSetWhileHidden`)
in `LabelTests.Windows.cs` to verify that showing a previously hidden
label with formatted text does not hang or crash the UI.
* Added necessary `using` directives for `Microsoft.Maui.Controls` and
`Xunit` to support the new test.


<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #35527 

### Tested the behavior in the following platforms

- [x] Windows
- [ ] Android
- [ ] iOS
- [ ] Mac

| Before Issue Fix | After Issue Fix |
|----------|----------|
| <img width="1404" height="560" alt="BeforeFix35527"
src="https://github.com/user-attachments/assets/5701a105-c57f-4f84-be87-2e1eacfa97d1"
/> | <img width="1417" height="732" alt="AfterFix35527"
src="https://github.com/user-attachments/assets/f85350ef-43bb-47a6-8273-eb3446b81c95"
/> |
<!--
<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Sep 9, 2026
…on (#36828)

<!-- Please keep the note below for people who find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment whether this change resolves your
issue. Thank you!

This pull request addresses a critical bug where showing a `Label` with
formatted text after it has been hidden could cause the UI thread to
hang and eventually crash with an `OutOfMemoryException`. The fix
introduces a guard against zero or negative line heights in the
`RecalculateSpanPositions` method. Additionally, a new test is added to
ensure this scenario is handled correctly.

### Description of Change:
**Bug fix for line height calculation:**

* Added a guard in `RecalculateSpanPositions` (in
`FormattedStringExtensions.cs`) to break out of the loop if a zero or
negative line height is encountered, preventing infinite loops and
memory issues when a `TextBlock` is measured while collapsed or hidden.

**Testing improvements:**

* Added a test
(`FormattedTextDoesNotHangOrCrashWhenLabelIsShownAfterBeingSetWhileHidden`)
in `LabelTests.Windows.cs` to verify that showing a previously hidden
label with formatted text does not hang or crash the UI.
* Added necessary `using` directives for `Microsoft.Maui.Controls` and
`Xunit` to support the new test.


<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #35527 

### Tested the behavior in the following platforms

- [x] Windows
- [ ] Android
- [ ] iOS
- [ ] Mac

| Before Issue Fix | After Issue Fix |
|----------|----------|
| <img width="1404" height="560" alt="BeforeFix35527"
src="https://github.com/user-attachments/assets/5701a105-c57f-4f84-be87-2e1eacfa97d1"
/> | <img width="1417" height="732" alt="AfterFix35527"
src="https://github.com/user-attachments/assets/f85350ef-43bb-47a6-8273-eb3446b81c95"
/> |
<!--
<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 25, 2026

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — e39f983a Deployed Jul 27, 2026 by SubhikshaSf4851 via conclusion #964
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-label Label, Span community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/windows s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Label with FormattedText crashes with OutOfMemoryException in RecalculateSpanPositions on Windows when text exceeds ~150 characters

6 participants