Skip to content

[Text] Make sure TryGetGlyphTypeface does not fail for concurrent access#21269

Merged
MrJul merged 8 commits into
AvaloniaUI:masterfrom
Gillibald:fixes/tryGetGlyphTypefaceRace
May 15, 2026
Merged

[Text] Make sure TryGetGlyphTypeface does not fail for concurrent access#21269
MrJul merged 8 commits into
AvaloniaUI:masterfrom
Gillibald:fixes/tryGetGlyphTypefaceRace

Conversation

@Gillibald

@Gillibald Gillibald commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

What does the pull request do?

Prevent FontManager.TryGetGlyphTypeface failures under concurrent access by making font collection retrieval/creation more concurrency-safe, and add unit tests that exercise concurrent embedded-font lookups.

What is the current behavior?

What is the updated/expected behavior with this PR?

How was the solution implemented (if it's not obvious)?

Checklist

Breaking changes

Obsoletions / Deprecations

Fixed issues

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 WIP PR aims to prevent FontManager.TryGetGlyphTypeface failures under concurrent access by making font collection retrieval/creation more concurrency-safe, and adds a unit test that exercises concurrent embedded-font lookups.

Changes:

  • Update FontManager.TryGetFontCollection to use _fontCollections.GetOrAdd(...) when retrieving/creating system and embedded font collections.
  • Add a new unit test that repeatedly forces embedded font collection recreation and performs concurrent TryGetGlyphTypeface calls.

Reviewed changes

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

File Description
src/Avalonia.Base/Media/FontManager.cs Switches font collection caching logic to ConcurrentDictionary.GetOrAdd for concurrent access.
tests/Avalonia.Base.UnitTests/Media/FontManagerTests.cs Adds a concurrency regression test for embedded font lookups.

Comment thread src/Avalonia.Base/Media/FontManager.cs Outdated
Comment thread tests/Avalonia.Base.UnitTests/Media/FontManagerTests.cs Outdated
Comment thread tests/Avalonia.Base.UnitTests/Media/FontManagerTests.cs Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@MrJul MrJul added bug area-textprocessing backport-candidate-12.0.x Consider this PR for backporting to 12.0 branch labels Apr 27, 2026
@Gillibald Gillibald requested a review from Copilot May 12, 2026 11:27
@Gillibald Gillibald changed the title [WIP] Make sure TryGetGlyphTypeface does not fail for concurrent access [Text] Make sure TryGetGlyphTypeface does not fail for concurrent access May 12, 2026

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

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

Comment thread src/Avalonia.Base/Media/FontManager.cs
Comment thread src/Avalonia.Base/Media/FontManager.cs Outdated
Comment thread tests/Avalonia.Base.UnitTests/Media/FontManagerTests.cs Outdated
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0065329-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

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

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

Comment thread tests/Avalonia.Base.UnitTests/Media/FontManagerTryGetFontCollectionTests.cs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0065335-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@MrJul MrJul added this pull request to the merge queue May 15, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 15, 2026
@MrJul MrJul added this pull request to the merge queue May 15, 2026
Merged via the queue into AvaloniaUI:master with commit 50a22e9 May 15, 2026
11 checks passed
MrJul pushed a commit to MrJul/Avalonia that referenced this pull request May 28, 2026
…ess (AvaloniaUI#21269)

* Make sure TryGetGlyphTypeface does not fail for concurrent access

* Update tests/Avalonia.Base.UnitTests/Media/FontManagerTests.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update gitignore

* Make TryGetFontCollection more robust and add unit tests

* Introdcue GetOrCreateFontCollection helper for safe disposal of losing instances

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@MrJul MrJul added backported-12.0.x and removed backport-candidate-12.0.x Consider this PR for backporting to 12.0 branch labels May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants