Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential crash when binding to or replacing RoslynCodeEditor.Document #442

Open
lennartb- opened this issue Sep 24, 2022 · 0 comments
Open
Labels

Comments

@lennartb-
Copy link

When binding to the Document property, or manually setting the Document property and then adding text and scrolling a bit, I can consistently reproduce a crash in AvalonEdit. I think this is caused by

var markersAtOffset = GetMarkersAtOffset(offset);

Stacktrace:

ICSharpCode.AvalonEdit.dll!ICSharpCode.AvalonEdit.Document.TextDocument.GetLineByNumber(int number) Line 894
ICSharpCode.AvalonEdit.dll!ICSharpCode.AvalonEdit.Document.TextDocument.GetOffset(int line, int column) Line 939
RoslynPad.Editor.Windows.dll!RoslynPad.Editor.TextMarkerService.EditorOnToolTipRequest(object sender, RoslynPad.Editor.ToolTipRequestEventArgs args) Line 86	C#

(the package does not seem up to date with the sources here)
Repro:

<Window
    x:Class="WpfApp1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:editor="clr-namespace:RoslynPad.Editor;assembly=RoslynPad.Editor.Windows"
    Title="MainWindow"
    Width="800"
    Height="450">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <editor:RoslynCodeEditor
            Name="Editor"
            Grid.Row="0"
            Document="{Binding Document}"
            FontSize="24"
            WordWrap="True" />
    </Grid>
</Window>
public partial class MainWindow : Window
{
    public TextDocument Document { get; } = new TextDocument();
    public MainWindow()
    {
        InitializeComponent();
        DataContext = this;
        Document = new TextDocument();
        Document = new TextDocument();
        Document = new TextDocument();
        Document = new TextDocument();
        Document = new TextDocument();
    }
}

Then start the app, write some text (including ~10 newlines) and use the scroll wheel on the mouse to scroll a couple of seconds up and down.

I think it's due to TextMarkerService caching the initial Document, and not updating its local copy when the Document of the Editor is replaced. This causes GetMarkersAtOffset called with an offset that isn't present in its cached version.

Version
OS: Win 11
NuGet RoslynPad.Editor.Windows 1.2.0

@aelij aelij added the bug label Oct 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants