Gettings D3DERR_INVALIDCALL

Started by
7 comments, last by Mike.Popoloski 13 years, 7 months ago
Hello,

I'm using vb.net with SlimDX, and have a problem. When creating the device, it gives me this error:

SlimDX.Direct3D9.Direct3D9Exception: D3DERR_INVALIDCALL: Invalid call (-2005530516)
at SlimDX.Result.Throw[T](Object dataKey, Object dataValue)
at SlimDX.Result.Record[T](Int32 hr, Boolean failed, Object dataKey, Object dataValue)
at SlimDX.Direct3D9.Device..ctor(Direct3D direct3D, Int32 adapter, DeviceType deviceType, IntPtr controlHandle, CreateFlags createFlags, PresentParameters[] presentParameters)
at SmallGame.Form1.initializeGraphics() in C:\Users\Rene\Documents\Visual Studio 2010\Projects\SmallGame\SmallGame\Form1.vb:line 24
at SmallGame.Form1.Form1_Load(Object sender, EventArgs e) in C:\Users\Rene\Documents\Visual Studio 2010\Projects\SmallGame\SmallGame\Form1.vb:line 38

This is my code:
    Public Sub initializeGraphics()        DEVICE_PARAMETERS = New PresentParameters        DEVICE_PARAMETERS.BackBufferCount = 1        DEVICE_PARAMETERS.BackBufferFormat = SlimDX.Direct3D9.Format.X8B8G8R8        DEVICE_PARAMETERS.BackBufferHeight = Screen.PrimaryScreen.Bounds.Height        DEVICE_PARAMETERS.BackBufferWidth = Screen.PrimaryScreen.Bounds.Width        DEVICE_PARAMETERS.Windowed = True        DEVICE_PARAMETERS.SwapEffect = SwapEffect.Copy        ENGINE = New Direct3D        DEVICE = New Device(ENGINE, 0, DeviceType.Hardware, Me.Handle, CreateFlags.HardwareVertexProcessing, DEVICE_PARAMETERS)    End Sub


I've searched, and found some other topics with the same problem. This one. seems to have the same problem. Thier sulution was to call "ZeroMemory" on the DEVICE_PAMAMETERS, after doing "= New PresentParameters", but I don't know how to get the handle of an variable in vb.net.

Please help me,
-René
Advertisement
I can't do VB.Net, but I can tell you what you can do instead of ZeroMemory.
Just search in the documentation for the DEVICE_PARAMETERS-Struct and set every single variable you see there to Zero.
ZeroMemory does basically the same.

Don't blame me if there is something similar to ZeroMemory in VB.Net, I've never done it. ;)
Quote:Original post by mind in a box
I can't do VB.Net, but I can tell you what you can do instead of ZeroMemory.
Just search in the documentation for the DEVICE_PARAMETERS-Struct and set every single variable you see there to Zero.
ZeroMemory does basically the same.

Don't blame me if there is something similar to ZeroMemory in VB.Net, I've never done it. ;)


Doesn't make a lot of sense... There is an ZeroMemory function in vb.net, but as I said, I just don't know how to get the handle/address of the variable.
    <DllImport("kernel32.dll")> _    Public Shared Sub ZeroMemory(ByVal addr As IntPtr, ByVal size As IntPtr)    End Sub
I'm not a VB person, either, but it's probably something like:

ZeroMemory(DEVICE_PARAMETERS, Size)

Size is a bit more difficult and I'm just parroting what I found by googling. This might work:

Size = System.Runtime.InteropServices.Marshal.SizeOf(DEVICE_PARAMETERS)

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Quote:Original post by Buckeye
I'm not a VB person, either, but it's probably something like:

ZeroMemory(DEVICE_PARAMETERS, Size)

Size is a bit more difficult and I'm just parroting what I found by googling. This might work:

Size = System.Runtime.InteropServices.Marshal.SizeOf(DEVICE_PARAMETERS)


Well, this is the code I have:
ZeroMemory(DEVICE_PARAMETERS, Marshal.SizeOf(DEVICE_PARAMETERS))

But the problem is, the first variable has to be an IntPtr (Or just be the handle of the variable), but idk how to get that.
Did you find anything useful when you googled? I'm assuming you're working to try to solve the problem, also. I got 106,000 hits for "vb.net intptr handle variable."

This one seems to have some info.

If you're not familiar with VB, then perhaps the easiest approach is what mind in a box suggests.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Quote:Original post by Buckeye
Did you find anything useful when you googled? I'm assuming you're working to try to solve the problem, also. I got 106,000 hits for "vb.net intptr handle variable."

This one seems to have some info.

If you're not familiar with VB, then perhaps the easiest approach is what mind in a box suggests.


I have not found the article you have right there. I am very familiar to VB.Net, and have implemented it like so:
        DEVICE_PARAMETERS = New SlimDX.Direct3D9.PresentParameters        Dim VarHandle As IntPtr = GCHandle.ToIntPtr(GCHandle.Alloc(DEVICE_PARAMETERS))        ZeroMemory(VarHandle, Marshal.SizeOf(VarHandle))

It does however not work.
I have also tried what MindInABox said, and that also does not work. Keeps returning the same error.
You have Windowed set to True but you don't set the window handle. I'm supposing that VB requires that in the present parameters.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

First of all, ZeroMemory is a macro. You won't be able to P/Invoke it.

Second, no where is it indicated that clearing out the memory is the problem. All you have is an InvalidCall result, which is so generic that it can mean anything from an invalid parameter to your graphics adapter not supporting a given setting. All types get their memory cleared in .NET anyway, so ZeroMemory isn't going to help you.

Your actual problem is probably either an invalid back buffer format, or that your graphics card doesn't support the chosen settings. Enable the debug runtimes and see if Direct3D gives any additional information about what is going wrong.
Mike Popoloski | Journal | SlimDX

This topic is closed to new replies.

Advertisement