Sorry, the Forum is closed :(

Unfortunately, the forum is now closed.

Please read the following post for further details.

We apologize for the inconvenience.
The SharpDX team.
Welcome, Guest
Username: Password: Remember me
Welcome to the general discussions!
  • Page:
  • 1

TOPIC: How to debug a SharpDXException?

How to debug a SharpDXException? 2 years 10 months ago #1774

  • Posts:843 Thank you received: 1
  • xoofx's Avatar
  • xoofx
  • Administrator
Whenever there is a SharpDXException, it is almost directly related to an invalid COM result code returned by a method (called HRESULT). If you look on internet for the hexadecimal value of the result code (printed along the exception), for example search for "0x80070057 HRESULT" is equivalent to E_INVALIDARG. But this alone is often not enough to make a clear diagnostic.

Most of DirectX APIs often come with a Debug Layer that is able to print additional information about such an error. This is extremely helpful to resolve most of the errors. APIs like Direct3D11, Direct3D10, Direct3D9 and a couple of other APIs provides a way to get these debug messages.

In order to get these messages, you need to:

1) Turn-on debugging information on the device

Using Direct3D11, simply pass DeviceCreationFlags.Debug when creating a Device like this:
    d3d11Device = new SharpDX.Direct3D11.Device(DriverType.Hardware, DeviceCreationFlags.Debug);
Using the Toolkit, you need to set DeviceCreationFlags on the instance of GraphicsDeviceManager like this:
    deviceManager = new GraphicsDeviceManager(this);
    deviceManager.DeviceCreationFlags = DeviceCreationFlags.Debug;

2) "Enable native code debugging" on your project

Go to the settings of the EXE project to debug:
  • On Windows Desktop, Project settings -> Debug -> Enable native code debugging
  • On Windows Store App, Project settings -> Debug -> Debugger Type = Mixed (Native & Managed)

3) Run your application in Debug mode from Visual Studio

And check the output log of Visual Studio in the Output Log tab. You will get this kind of error/warnings:
D3D11 ERROR: ID3D11Device::CreateVertexShader: Invalid shader version provided: vs_4_0 [ STATE_CREATION ERROR #167: CREATEVERTEXSHADER_INVALIDSHADERTYPE]
From this it is much easier to make a clear diagnostic of a problem, though not all DirectX APIs are providing such a level of details, but make sure that there is a debug layer/and also check for the result code on internet before asking the reason of an exception in the forum. But most of the time, it is easily fixable with the provided information.

This debug layer can report also active live COM objects (reported just before the application is closing).

Check also Recommandations for debugging? for additional information.
The administrator has disabled public write access.

Re: How to debug a SharpDXException? 2 years 10 months ago #1782

  • Posts:55
  • zagy's Avatar
  • zagy
  • Senior Boarder
This topic should be pinned :)

Two notes:
1. For Win8 Metro apps, the setting is "Debugger type: Mixed (Managed and Native)"
2. However, when debugging on ARM/RT devices, you can only select one type of debugging (Managed OR Native). So it usually takes a little switching...
The administrator has disabled public write access.

Re: How to debug a SharpDXException? 2 years 7 months ago #3045

  • Posts:7
  • gdev1's Avatar
  • gdev1
  • Fresh Boarder
Does anyone know if its possible to get the additional DirectX output from a standalone executable?

By following the 3 instructions above I can get the output in the Output view in Visual Studio, but not in the console stdout/stderr of the executable that is produced.

I'm not sure what mechanism visual studio is using when it launches a debug executable that I'm not using from the commandline but its presumably related to step 2 or 3 below?
Last Edit: 2 years 7 months ago by gdev1.
The administrator has disabled public write access.
  • Page:
  • 1
Time to create page: 0.177 seconds