helix-toolkit: Hang when a screen is connected/disconnected

When using SharpDX WPF without SwapChainRendering the GUI will hang at surfaceD3D?.InvalidateD3DImage() in DX11ImageSourceRenderHost PostRender() method. This can be tested with the SimpleDemo Example for WPF, just unplug a screen and it will hang. We have tested it on 3 different machines with different hardware, all running Windows 10, and it happens on all of them.

if I change the SurfaceD3D_IsFrontBufferAvailableChanged method to the following it seems to work,

` private void SurfaceD3D_IsFrontBufferAvailableChanged(object sender, System.Windows.DependencyPropertyChangedEventArgs e) { if (EffectsManager == null) { return; }

Logger.Log(HelixToolkit.Logger.LogLevel.Warning, $"SurfaceD3D front buffer changed. Value = {(bool)e.NewValue}");
if ((bool)e.NewValue)
{
	frontBufferChange = false;
	try
	{
	        EndD3D();
	        if (surfaceD3D != null)
	        {
		        hasBackBuffer = false;
		        surfaceD3D.SetRenderTargetDX11(null);
		        // surfaceD3D.IsFrontBufferAvailableChanged -= SurfaceD3D_IsFrontBufferAvailableChanged;
		        RemoveAndDispose(ref surfaceD3D);
	        }
    
	        EffectsManager.DisposeAllResources();
	        EffectsManager.Reinitialize();
	}
	catch (Exception ex)
	{
		Logger.Log(HelixToolkit.Logger.LogLevel.Error, ex.Message);
	}
}
}

`

But I guess someone with actual knowledge of what the code I have removed does might see why this is a bad idea.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 40 (33 by maintainers)

Most upvoted comments

@kthyholdt @gregorsGit @eriove @oyvindse Hi all, I was finally able to reproduce some of the cases on monitor switch. I updated the PR to improve the recovery. Please try again.

I tested this PR now. Can´t get a black-screen or a crash, when switching resolutions or connecting an external pisplay. This is great for me. I´m happy.

Thanks.