• Advertisement
Sign in to follow this  

E_INVALIDARG with Device.CreateWithSwapChain

This topic is 2201 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello.

I am starting with DirectX and use SlimDX. I try to set up a device and swap chain. when calling Device.CreateWithSwapChain(...) i get an Direct3D11Exception "E_INVALIDARG: An invalid parameter was passed to the returning function (-2147024809)". I have tried many combinations of settings and compared my code to a couple of other examples but I cannot see what is wrong. Here is my code:


[CODE]
...

// create the swap chain description
swapChainDescription = new SwapChainDescription();

// set to a single back buffer
swapChainDescription.BufferCount = 1;

// create the mode description for the back buffer
modeDescription = new ModeDescription();

// set refresh rate
refreshRate = new Rational();
refreshRate.Numerator = numerator;
refreshRate.Denominator = denominator;
modeDescription.RefreshRate = refreshRate;

// set the buffer size
modeDescription.Width = form.Width;
modeDescription.Height = form.Height;

// set the scan line ordering and scaling to unspecified
modeDescription.ScanlineOrdering = DisplayModeScanlineOrdering.Unspecified;
modeDescription.Scaling = DisplayModeScaling.Unspecified;

// set the mode description of the back buffer
swapChainDescription.ModeDescription = modeDescription;

// set the usage of the back buffer
swapChainDescription.Usage = Usage.RenderTargetOutput;

// set the handle for the window to render to
swapChainDescription.OutputHandle = form.Handle;

// turn multisampling off
sampleDescription = new SampleDescription();
sampleDescription.Count = 1;
sampleDescription.Quality = 0;
swapChainDescription.SampleDescription = sampleDescription;

// fullscreen or windowed
swapChainDescription.IsWindowed = !fullscreen;

// discard the back buffer contents after presenting
swapChainDescription.SwapEffect = SwapEffect.Discard;

// don't set the advanced flags
swapChainDescription.Flags = SwapChainFlags.None;

// create the swap chain, device and device context
FeatureLevel[] featureLevels = new FeatureLevel[] { FeatureLevel.Level_11_0 };
if (!Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, featureLevels, swapChainDescription, out device, out swapChain).IsSuccess)
{
MessageBox.Show("Cannot create a DirectX 11 device und swap chain", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
deviceContext = device.ImmediateContext;

...
[/CODE]

with form being a SlimDX.Windows.RenderForm, numerator = 60, denominator = 1

I am pretty lost right now and hope someone can help me with this. Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
My graphics card is a NVIDIA GeForce GTX 460.

Here is the stacktrace:

[CODE]
bei SlimDX.Result.Throw[T](Object dataKey, Object dataValue)
bei SlimDX.Result.Throw[T](Object dataKey, Object dataValue)
bei SlimDX.Result.Record[T](Int32 hr, Boolean failed, Object dataKey, Object dataValue)
bei SlimDX.Direct3D11.Device.CreateWithSwapChain(Adapter adapter, DriverType driverType, DeviceCreationFlags flags, FeatureLevel[] featureLevels, SwapChainDescription swapChainDescription, Device& device, SwapChain& swapChain)
bei SlimDX.Direct3D11.Device.CreateWithSwapChain(DriverType driverType, DeviceCreationFlags flags, FeatureLevel[] featureLevels, SwapChainDescription swapChainDescription, Device& device, SwapChain& swapChain)
bei ProjectName.Rendering.DirectX.Initialize(RenderForm form, Boolean vSync, Boolean fullscreen, Single screenNear, Single screenFar) in C:\Users\Name\documents\visual studio 2010\Projects\ProjectName\ProjectName\Rendering\DirectX.cs:Zeile 178.
bei ProjectName.Program.Main(String[] args) in C:\Users\Name\documents\visual studio 2010\Projects\ProjectName\ProjectName\Program.cs:Zeile 42.
bei System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bei System.Threading.ThreadHelper.ThreadStart()
[/CODE]

Share this post


Link to post
Share on other sites
Try turning on the debug runtimes from the DirectX Control Panel; that should give you a more useful error message in the debug output window (Or, use DebugView) when a D3D error occurs.

Share this post


Link to post
Share on other sites
Thank you for the hint. I received these three messages in DebugView:

[CODE]
[556] D3D11: ERROR: ID3D11Device::CreateTexture2D: A Texture2D does not support the following Format (0, UNKNOWN). [ STATE_CREATION ERROR #92: CREATETEXTURE2D_UNSUPPORTEDFORMAT ]
[556] D3D11: ERROR: ID3D11Device::CreateTexture2D: The format (0, UNKNOWN) cannot be bound as a RenderTarget, or cast to a format that could be bound as a RenderTarget. Therefore this format does not support D3D11_BIND_RENDER_TARGET. [ STATE_CREATION ERROR #92: CREATETEXTURE2D_UNSUPPORTEDFORMAT ]
[556] D3D11: ERROR: ID3D11Device::CreateTexture2D: Returning E_INVALIDARG, meaning invalid parameters were passed. [ STATE_CREATION ERROR #104: CREATETEXTURE2D_INVALIDARG_RETURN ][/CODE]

I did not set the property Format in ModeDescription. Now I use Format.B8G8R8A8_UNorm and the device / swap chain creation works. Thanks soo much.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement