6
\$\begingroup\$

I am developping an application using SharpDX and on one of my machines the call

_swapChain = new SwapChain(factory, _device, desc);

fails with the error message

HRESULT: [0x887A0001], Module: [SharpDX.DXGI], ApiCode: [DXGI_ERROR_INVALID_CALL/InvalidCall], Message: Unknown

When I googled the error I found this where it states:

DXGI_ERROR_INVALID_CALL (0x887A0001)

The application provided invalid parameter data; this must be debugged and fixed before the application is released.

But how?

The error message does not give me any indication whatsoever to why the creation failed.

I checked the debug layer output but that only shows Info. No Warning, no Error, nothing. The factory and the device are created just fine and I tried several combinations of parameters in my SwapChainDescription but the error always remains the same.

How am I supposed to find out what triggers the error?

Just to be clear: I am not so much looking for a solution for my specific problem as I am wondering how I would go about debugging such a problem in general.

This is the boiled down code:

const int MAXFPS = 60;
const Format PIXELFORMAT = Format.R8G8B8A8_UNorm;

// Create device
_device = new Device(DriverType.Hardware, DeviceCreationFlags.None); // Or DeviceCreationFlags.Debug

// SwapChain description
var desc = new SwapChainDescription()
{
    BufferCount = 2, // I tried 1 too
    ModeDescription = new ModeDescription(_renderSize.Width, _renderSize.Height,
                                          new Rational(MAXFPS, 1), PIXELFORMAT),
    IsWindowed = true,
    OutputHandle = _hwnd,
    SampleDescription = _samples,
    SwapEffect = SwapEffect.Discard,
    Usage = Usage.RenderTargetOutput
};

// Create SwapChain
var factory = new SharpDX.DXGI.Factory();
_swapChain = new SwapChain(factory, _device, desc);

I confirmed the sample description is valid using

_device.CheckMultisampleQualityLevels(PIXELFORMAT, _samples.Count) > _samples.Quality

(though, those are 1 and 0 anyway), that the format is supported using

_device.CheckFormatSupport(PIXELFORMAT).HasFlag(FormatSupport.RenderTarget)

and also checked that

_hwnd != IntPtr.Zero
_renderSize.Width > 0
_renderSize.Height > 0

What else to check?


Update: I was able to fix the problem following the advice from here:

I changed this

Device device = new Device(DriverType.Hardware, DeviceCreationFlags.None);
Factory factory = new Factory();
SwapChain swapChain = new SwapChain(factory, device, desc);

to

Factory factory = new Factory();
var adapter = factory.GetAdapter(0);
Device device = new Device(adapter, DeviceCreationFlags.None);
SwapChain swapChain = new SwapChain(factory, device, desc);
\$\endgroup\$
2
\$\begingroup\$

This typically happens when calling a D3D function with an invalid parameter (e.g. a NULL pointer where not permitted). This is exactly what the SwapChain's constructor documentation says:

InvalidCallException The method call is invalid. For example, a method's parameter might contain an invalid value.

You need to check one by one the parameters you provide to this function, especially in this case you need to check that the present parameters you provide are correct (see the C++ doc for those, it's providing lots of details).

In your case, as it's failing on one specific machine, you're probably asking for stuff that isn't supported by its hardware, e.g. a D3D feature level too high for the graphics chip.

It sometimes help to check the samples provided by Microsoft to check what parameters they're passing, and see the differences that could cause the issue.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.