Skip to content

Crash in TextBoxView.cs related to wrapping. #11481

@katedsouza

Description

@katedsouza

Description

I created this small application so that I could report the problem (see the reproduction steps). The callstack is different in this particular case to the crash that I am having in my real application, but the origin is the same:

  • Text in a TextBox that consists of a single space followed by a long word so that the text wrapping results in a top line with a single space and 2 more lines.
  • Type a space at the beginning of the 3rd line so that the text wrapping will now result in 2 lines, the 1st line consisting of a space followed by the characters that were previously on the 2nd line, and the 2nd line consisting of the characters that were previously on the 3rd line.

The crashes are always in TextBoxView.cs.

What seems to happen is that the space gets positioned at the end of the 2nd line, so we have a 1st line with a single space, a 2nd line with o's then a space, then a 3rd line with the remaining o's. If the wrapping algorithm was applied to the whole text then we would have a 1st line with a space following by o's, then a 2nd line with the remaining o's. When something happens that uses the wrapping algorithm on the beginning of the text, the result does not match the current line metrics causing a crash.

Is it possible to have a fix for this problem?

Thanks.

Reproduction Steps

Create a WPF application with this MainWindow:

<Window x:Class="MyTestApp.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:MyTestApp" mc:Ignorable="d" Title="MainWindow" Height="200" Width="200"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <TextBox x:Name="MyTextBox" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" VerticalContentAlignment="Top" FontSize="14.0" TextAlignment="Left" TextWrapping="Wrap"> </TextBox> </Grid> </Window>

  1. Run application (and DO NOT resize the window).
  2. Paste the text that is within the quotes here " oooooooooooooooooooooooo". (The result is 3 lines: first line has a single space, the second has lots of o characters and the last has 3 o characters.
  3. Place the cursor at the start of the third line and type a single space.
  4. Move the mouse cursor around the window (specifically over the first line).
  5. Application crashes with a FatalExecutionEngineError.

Expected behavior

No crash.

Actual behavior

In our application, the problem is a hard crash and our application simply disappears with no message.

Regression?

No response

Known Workarounds

We have no good workaround. It may seem that the workaround would be to not allow users to enter a second space in the TextBox, but the bug occurs in other circumstances i.e. if we have a mix of Arabic and Latin text, the crash can occur by entering a Latin character within the Arabic text.

Impact

No response

Configuration

No response

Other information

For your information, this particular TextBox is used to enter a character set for the creation of a font file. So in this case it is normal to have a long 'word' without spaces in between.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions