Starting with SlimDX.

Started by
3 comments, last by Billr17 15 years, 4 months ago
I'm currently trying to use SlimDX, but I'm getting an unhelpful 'Invalid Call' when trying to create the device - i.e. the very first step! I've looked at the examples, but they all use the huge 'SampleFramework' which is a nightmare to dig through. MiniTri, the one example that doesn't, crashes whenever I run it. My code is as follows:

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Size = new Size(800, 600);
            IntPtr windowHandle = this.Handle;

            Direct3D direct3D = new Direct3D();

            PresentParameters presentParams = new PresentParameters();
            presentParams.BackBufferWidth = 800;
            presentParams.BackBufferHeight = 600;
            presentParams.SwapEffect = SwapEffect.Discard;
            presentParams.Windowed = true;

            Device device = new Device(direct3D, 0, DeviceType.Hardware, windowHandle, CreateFlags.HardwareVertexProcessing, presentParams);

            device.BeginScene();
            device.Clear(ClearFlags.Target, 0, 0F, 0);
            device.EndScene();

            device.Present();
        }
Can anyone see why the code might be crashing on the Device instantiation? The exception, as if it helps, reads 'D3DERR_INVALIDCALL: Invalid call (-2005530516)' Also, as a side question, are there any issues with getting SlimDX working in a WPF application? Thanks! :)
Advertisement
Enable unmanaged debugging for your project and create the device with the debug flag. This will cause D3D to emit diagnostics to the output window.

An invalid call often means the parameters you passed to the function are nonsense. The MiniTri sample is likely crashing for exactly the same reason (since it's "mini" it does no error checking; an invalid call exception will be uncaught and terminate the application).

Are you sure your machine supports the parameters you assigned to the present parameters? Remember that this is C#, so value types (like PresentParameters) are default-initialized. For most of the values in that structure, this will be the equivalent of a zero, which may not correspond to a sane value. It is best to explicitly set all fields of PresentParameters when trying to diagnose this kind of issue.
Thanks, I'll try that!

Any help with my side question - will I encounter any issues trying to get this working with WPF? I think WPF uses DX for its own rendering, and I've heard of 'issues' getting the two working together, but I don't know to what extent.

Thanks again. :)

!!! EDIT !!! : When you say 'and create the device with the debug flag', how do I set this? I've looked through the CreateFlags enumeration, and the PresentParameters class, and see no reference to a debug flag.

[Edited by - Bargaust on December 19, 2008 5:43:36 PM]
you can find the debug mode setting in the directx configuration tool, given along the DirectX SDK.

http://slimdx.mdxinfo.com/wiki/index.php?title=Debugging_Tips
Quote:Original post by Bargaust
will I encounter any issues trying to get this working with WPF? I think WPF uses DX for its own rendering, and I've heard of 'issues' getting the two working together, but I don't know to what extent.


Prior to .NET 3.5 SP1, using WPF and DirectX together was a problem. In .NET 3.5 SP1, Microsoft exposed the ability to draw to a surface using the new D3DImage image source. Basically you can apply the surface as a brush to anything you want. :-)

Dr. WPF posted a very good article outlining the usage of the D3DImage with DirectX. If you want to understand how the image source works, I would highly recommend giving it a read.

Introduction to D3DImage

Also check out this post on GameDev:WPF D3DImage with SlimDx.

-Bill

This topic is closed to new replies.

Advertisement