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:
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).
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?
1 year 9 months ago #3045