-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[v12-rc1] Layout deadlock in headless mode #21022
Description
Describe the bug
I am migrating a PDF Viewer application from Avalonia 11.3.13 to Avalonia 12.0.0-rc1 and I have observed a deadlock issue in the tests.
It took me some time to identify the issue that causes this and isolate it to create minimalistic repro project to demonstrate it.
The problem seems to be related to the new TextShaper implementation, when using LineBreak inside TextBlock in XAML.
<TextBlock TextWrapping="Wrap" FontSize="14">
<Run Text="Line one"/><LineBreak/>
<Run Text="Line two"/><LineBreak/>
<Run Text="Line three"/>
</TextBlock>
When running the test, I can see unlimited memory consumption, that basically drain all the resources and never finish.
I have paused the test case to see in which state the application is stuck, which is between TextBlock.CreateTextLayout, TextLayout.CreateTextLines and HarfBuzzTextShaper.ShapeText.
When switching the same code to 11.3.13 it's working as expected.
When I remove the LineBreak from XAML it's also working as expected.
To Reproduce
The reproduction scenario contains one XAML window with TextBlock, Runs and LineBreaks.
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="HeadlessLineBreakRepro.TestWindow"
Title="Repro" Width="400" Height="300">
<StackPanel Margin="20">
<!-- This TextBlock with Run + LineBreak causes a deadlock in headless mode -->
<TextBlock TextWrapping="Wrap" FontSize="14">
<Run Text="Line one"/><LineBreak/>
<Run Text="Line two"/><LineBreak/>
<Run Text="Line three"/>
</TextBlock>
</StackPanel>
</Window>
In the tests I am using headless without any specific options.
public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure<App>()
.UseHeadless(new AvaloniaHeadlessPlatformOptions());
After this a simple test case scenario to show the window.
[AvaloniaTest]
public void RunWithLineBreak_InAxaml_ShouldNotDeadlock()
{
var window = new TestWindow();
window.Show(); // <-- DEADLOCKS HERE
window.Close();
Assert.Pass();
}
Full source code, XAML, tests in the zip attachment below.
avalonia-headless-linebreak-repro.zip
Expected behavior
There should be no excessive memory consumption and this simple test should finish in one second.
The headless mode should closely resemble the actual desktop application behavior, so that I am able to catch most of the bugs in the automated tests.
Avalonia version
12.0.0-rc1
OS
Windows
Additional context
No response