question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NullReferenceException RenderLoop.TimerTick hiding a ContextMenu

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
maxkatz6commented, Jan 3, 2021

@lordzomat In your ProgressWindow you have following code:

private void Execute()
{
    worker.RunWorkerAsync();
    ShowDialog(this);
}

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.

0reactions
lordzomatcommented, Jan 3, 2021

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found