0

Unable to run WPF.SharpDX demos

Van 3 years ago in Question updated 3 years ago 1

I am trying to evaluate helixtoolkit for use in an existing WPF application. I cloned the repo and compiled everything, but when I try to execute any of the WPF.SharpDX examples I get an error message in the application:


System.InvalidOperationException: Cannot call this method without a back buffer.
   at System.Windows.Interop.D3DImage.AddDirtyRect(Int32Rect dirtyRect)
   at HelixToolkit.Wpf.SharpDX.DPFCanvas.UpdateAndRender() in C:\helix-toolkit\Source\HelixToolkit.Wpf.SharpDX\Controls\DPFCanvas.cs:line 753


However, I think this is a bit misleading. When I look at the code, it is failing on line 102 of DX11ImageSource:


this.renderTarget = new Texture(DX11ImageSource.device, target.Description.Width, target.Description.Height, 1, Usage.RenderTarget, format, Pool.Default, ref handle);      

With the following exception thrown: 


'SharpDX.SharpDXException' in SharpDX.dll
HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect.


I even tried making my own possibly simpler project and using NuGet to import the helixtoolkit libraries and I get the same error. At home I can execute everything on my personal computer so it appears to be some (mis)configuration on my work laptop. Both machines are Windows 10, using VS2017 with AFAIK updated drivers. I'm not sure where to go from here to diagnose the error.


I have also tried Microsoft's WPF DirectX Extensions (https://github.com/Microsoft/WPFDXInterop) and it works properly. Finally, I tried compiling SharpDX but it doesn't include any sample code for me to run. If anyone has any suggestions, I'd love to hear them.

SharpDX WPF

Well isn't this how it goes? I found the solution in: https://github.com/helix-toolkit/helix-toolkit/issues/282


As recommended there, I updated Effects.GetBestAdapter() line 135 to:

if ((bestAdapter == null) || (videoMemory > bestVideoMemory) && (systemMemory > bestSystemMemory))


and now the examples run. I guess these fixes have not been merged into the repo yet?