NullReferenceException RenderLoop.TimerTick hiding a ContextMenu
See original GitHub issueI want to hide a context menu completely based on a property from my data source. The context menu works with the XAML below as expected but there are a lot of exceptions fired in the background by TimerTick if i do a right click on a tree view item where IsRootNode
is false
.
<ContextMenu IsVisible="{Binding IsRootNode}">
<MenuItem Header="Remove"></MenuItem>
</ContextMenu
The exception shown in debugging output:
[Visual] Exception in render loop: "System.NullReferenceException: Object reference not set to an instance of an object.
at Avalonia.Skia.FramebufferRenderTarget.CreateDrawingContext(IVisualBrushRenderer visualBrushRenderer)
at Avalonia.Rendering.DeferredRenderer.EnsureDrawingContext(IDrawingContextImpl& context)
at Avalonia.Rendering.DeferredRenderer.UpdateRenderLayersAndConsumeSceneIfNeeded(IDrawingContextImpl& context, Boolean recursiveCall)
at Avalonia.Rendering.DeferredRenderer.Render(Boolean forceComposite)
at Avalonia.Rendering.RenderLoop.TimerTick(TimeSpan time)" (Avalonia.Rendering.RenderLoop #25871395)
The complete XAML for the TreeView containing the context menu:
<TreeView x:Name="NavigationTreeView" Grid.Row="0" Grid.Column="0" Items="{Binding TreeNodes}">
<TreeView.DataTemplates>
<TreeDataTemplate DataType="models:TreeNode" ItemsSource="{Binding Nodes}">
<StackPanel Orientation="Horizontal">
<StackPanel.ContextMenu>
<ContextMenu IsVisible="{Binding IsRootNode}">
<MenuItem Header="Remove"></MenuItem>
</ContextMenu>
</StackPanel.ContextMenu>
<Image Source="{Binding Image}"/>
<TextBlock Margin="5,0,0,0" Foreground="Black" Text="{Binding DisplayName}"/>
<TextBlock Margin="10,0,0,0" Foreground="Gray" Text="{Binding SizeDisplayValue, StringFormat='({0})'}" HorizontalAlignment="Right"/>
</StackPanel>
</TreeDataTemplate>
</TreeView.DataTemplates>
</TreeView>
Expected behavior No exceptions to occur.
Desktop:
- OS: Windows 10
- Version: 0.9.12
- .NET Core 3.1
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Not Working! · Issue #26 · CefNet/ ...
Error Info: [Visual] Exception in render loop: "System.NullReferenceException: Object reference not set to an instance of an object.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@lordzomat In your ProgressWindow you have following code:
Where you tries to open Dialog window with itself as a owner. Window can’t own itself, you need to pass another windows as a first parameter in ShowDialog method. In your case it probably should be MainWindow. Or you can use “Show” method without “Dialog” part that doesn’t requires owner to be presented.
If it worked before, it must have been undefined behavior that is also a bug, in my opinion. On other hand, ShowDialog should throw a clear exception, if owner parameter is invalid.
@maxkatz6 thanks for the hint, that did the trick. I did a few tests and i cannot reproduce the issue with
0.10.0-rc1
so i think the issue can be closed.