# Gettings D3DERR_INVALIDCALL

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

## Recommended Posts

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.

-René

##### Share on other sites
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. ;)

##### Share on other sites
Quote:
 Original post by mind in a boxI 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

##### Share on other sites
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)

##### Share on other sites
Quote:
 Original post by BuckeyeI'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.

##### Share on other sites
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.

##### Share on other sites
Quote:
 Original post by BuckeyeDid 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.

##### Share on other sites
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.

##### Share on other sites
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.

• 23
• 10
• 19
• 15
• 14