bepu / bepuphysics2

Pure C# 3D real time physics simulation library, now with a higher version number.
Apache License 2.0
2.35k stars 272 forks source link

Getting SharpDX.SharpDXException while running demo with Visual Studio 2019 #68

Open alam123 opened 5 years ago

alam123 commented 5 years ago

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

Source=SharpDX StackTrace: at SharpDX.Result.CheckError() at SharpDX.Direct3D11.Device.CreateVertexShader(IntPtr shaderBytecodeRef, PointerSize bytecodeLength, ClassLinkage classLinkageRef, VertexShader vertexShaderOut) at SharpDX.Direct3D11.VertexShader..ctor(Device device, Byte[] shaderBytecode, ClassLinkage linkage) at DemoRenderer.ShapeDrawing.RayTracedRenderer`1..ctor(Device device, ShaderCache cache, String shaderPath, Int32 maximumInstancesPerDraw) in C:\Work\Games\bepuphysics2-master\DemoRenderer\ShapeDrawing\RayTracedRenderer.cs:line 70 at DemoRenderer.Renderer..ctor(RenderSurface surface) in C:\Work\Games\bepuphysics2-master\DemoRenderer\Renderer.cs:line 71 at Demos.GameLoop..ctor(Window window) in C:\Work\Games\bepuphysics2-master\Demos\GameLoop.cs:line 33 at Demos.Program.Main(String[] args) in C:\Work\Games\bepuphysics2-master\Demos\Program.cs:line 16

RossNordby commented 5 years ago

What operating system and video card are you using? Any DX11 class GPU should suffice, and in theory windows 7 or above should work. (There's been one report that windows 7 didn't work, though; not sure why at this point.)

You can also enable the directx debug layer to get a better description of the issue.

  1. Run in debug mode to make the demos choose to create the device with the debug layer enabled, and then
  2. modify the Demos/Properties/launchSettings.json to enable native debugging:
    {
    "profiles": {
    "Demos": {
      "commandName": "Project",
      "nativeDebugging": true
    }
    }

    Loading all the symbols will take a little while at first, but in the visual studio debug output window, you can then see things like:

D3D11 ERROR: ID3D11Device::CreateBuffer: When createing a buffer with the MiscFlag D3D11_RESOURCE_MISC_BUFFER_STRUCTURED specified, the ByteWidth must be a multiple of the StructureByteStride. [ STATE_CREATION ERROR #2097339: CREATEBUFFER_INVALIDSTRUCTURESTRIDE]

fxgenstudio commented 5 years ago

SharpDX.SharpDXException HResult=0x80070057 Message=HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: Paramètre incorrect.

Source=SharpDX StackTrace: at SharpDX.Result.CheckError() at SharpDX.Direct3D11.Device.CreateBuffer(BufferDescription& descRef, Nullable1 initialDataRef, Buffer bufferOut) at SharpDX.Direct3D11.Buffer..ctor(Device device, BufferDescription description) at DemoRenderer.StructuredBuffer1.CreateBufferForSize(Int32 size, Buffer& newBuffer, ShaderResourceView& newSRV, UnorderedAccessView& newUAV) in E:\Downloaded\bepuphysics2\DemoRenderer\StructuredBuffer.cs:line 82 at DemoRenderer.StructuredBuffer`1..ctor(Device device, Int32 initialCapacity, String debugName) in E:\Downloaded\bepuphysics2\DemoRenderer\StructuredBuffer.cs:line 76 at DemoRenderer.ShapeDrawing.MeshCache..ctor(Device device, BufferPool pool, Int32 initialSizeInVertices) in E:\Downloaded\bepuphysics2\DemoRenderer\ShapeDrawing\MeshCache.cs:line 36 at DemoRenderer.ShapeDrawing.ShapesExtractor..ctor(Device device, ParallelLooper looper, BufferPool pool, Int32 initialCapacityPerShapeType) in E:\Downloaded\bepuphysics2\DemoRenderer\ShapeDrawing\ShapesExtractor.cs:line 35 at DemoRenderer.Renderer..ctor(RenderSurface surface) in E:\Downloaded\bepuphysics2\DemoRenderer\Renderer.cs:line 70 at Demos.GameLoop..ctor(Window window) in E:\Downloaded\bepuphysics2\Demos\GameLoop.cs:line 33 at Demos.Program.Main(String[] args) in E:\Downloaded\bepuphysics2\Demos\Program.cs:line 16

RossNordby commented 5 years ago

Unfortunately, I can't do much with the exception alone- it's sort of a catchall. I suspect there is some sort of hardware, OS, or maybe SDK incompatibility causing these, but to make progress toward confirming that I need to know more details: 1) What GPU are you using? 2) What OS version are you using? 3) What is the latest Windows SDK version you have installed? (There should be a Windows SDK Configuration Tool already installed which lists the SDKs on your computer) 4) Do you see any D3D11 debug layer WARNING or ERROR messages in the debug output when following the instructions above?

alam123 commented 5 years ago

My graphics card is I am using NVidia Quadro FX 580.

RossNordby commented 5 years ago

Unfortunately, that card does not support DX11, so that would explain the crash. The demos require DX11 to run. (The library itself, of course, has no GPU-related dependencies.)

RossNordby commented 5 years ago

For anyone checking this issue, I'm still seeing occasional reports that the demos fail on DX11 class GPUs running on windows 7. I don't have any win7 computers to test at the moment, so if anyone has one and is willing to do some diagnostics, it would be helpful.

The main things I'd like to know are 1) does it work at all on windows 7, and 2) if not, what errors is the debug layer spitting out? My first post in this thread describes how to enable the debug layer. Thanks to anyone who puts in the effort!

Basewq commented 4 years ago

Don't know if this should be in a separate issue or can be placed in here but I'm on a Win7 machine, but my error is slightly different:

DXGI ERROR: IDXGIFactory::CreateSwapChain: SwapEffect is unknown. [ MISCELLANEOUS ERROR #32: ]
Exception thrown at 0x000007FEFD16A06D in dotnet.exe: Microsoft C++ exception: _com_error at memory location 0x000000000037D860.
Exception thrown: 'SharpDX.SharpDXException' in SharpDX.dll
An unhandled exception of type 'SharpDX.SharpDXException' occurred in SharpDX.dll
HRESULT: [0x887A0001], Module: [SharpDX.DXGI], ApiCode: [DXGI_ERROR_INVALID_CALL/InvalidCall], Message: Unknown

As far as I can tell, SwapEffect.FlipDiscard isn't available for DX11. https://github.com/bepu/bepuphysics2/blob/a7b972d1755b60560f285dc33bc7accc2cecfe4b/DemoRenderer/RenderSurface.cs#L53

Changing it to just SwapEffect.Discard made the demo work on my machine.

RossNordby commented 4 years ago

Oops, good catch! FlipDiscard does indeed only work on win10. That's what I get for copying from the DX12 codebase :P

Fixed in 65b2c321cd8e32ce6ef2eda569015ab9281a7a61.

FrankBolleri commented 4 years ago

Hello! I face today the same issue, because i am running Windows on VMWare Fusion and DX11 is not supported by this environment. After several attempts, I see that if I use dxcpl utility to force WARP mode (I think is like a software emulation...) on "C:\Program Files\dotnet\dotnet.exe" it finally works.

DX WARP for bepuphysics2 Demo

It run pretty slow and absolutely not fluent.. but it works enough to study the library for me.

Hope this help.

RossNordby commented 4 years ago

Another potential cause: not having the SDK installed, and attempting to run in debug mode. By default, the demos renderer enabled the device debug layer, which would then fail on launch. Running in release would still work.

1751f48f16b5349afda3ec17e065b4ff89c0257e defaults the debug layer to off always.

To enable the debug layer to investigate other rendering issues, change the last parameter to true here: https://github.com/bepu/bepuphysics2/blob/1751f48f16b5349afda3ec17e065b4ff89c0257e/Demos/GameLoop.cs#L26

Squall-Leonhart commented 3 years ago

Theres another one caused by not having the W7 platform update installed that returns E_NOINTERFACE.