PDA

View Full Version : Very annoying DirectX error


cypher543
05-03-2006, 02:18 PM
I'm finally learning to work with DirectX... but the experience has not been good so far. I can't even get the device to start! I get the following error when I try to run my application:
Code: -2005530516
Message: Error in the application.
String: D3DERR_INVALIDCALL
I am using Visual Basic .NET 2005 Express and DirectX 9.0c. The code for my StartDirectX() method is below:
If deviceCaps.DeviceCaps.SupportsHardwareTransformAnd Light Then
newFlags = CreateFlags.HardwareVertexProcessing
Else
newFlags = CreateFlags.SoftwareVertexProcessing
End If

If deviceCaps.DeviceCaps.SupportsPureDevice And newFlags = CreateFlags.HardwareVertexProcessing Then
newFlags &= CreateFlags.PureDevice
End If

Dim presentParams As New PresentParameters
presentParams.SwapEffect = SwapEffect.Discard
presentParams.Windowed = True

d3dDevice = New Device(defaultAdapter, DeviceType.Hardware, ContagionForm.Handle.ToInt32, newFlags, presentParams)
All of my variables have been defined:
Dim d3dDevice As Device
Dim defaultAdapter As Integer = Manager.Adapters.Default.Adapter
Dim deviceCaps As Caps = Manager.GetDeviceCaps(defaultAdapter, DeviceType.Hardware)
Dim newFlags As CreateFlags
So what is the problem? I can't believe DirectX doesn't give any more detail than "Error in the application"! Any ideas?

BTW, I did search the forums (using the error code as the string) before I posted, but the only topic I found that seemed to be relevant went off topic into a discussion about a college professor and never provided a clear answer to the problem.

Jare
05-03-2006, 03:40 PM
newFlags &= CreateFlags.PureDevice
That might be it. Not really sure but looks like you're clearing everything except the PureDevice bit, when you probably want to SET the bit.

cypher543
05-03-2006, 04:18 PM
I thought that in VB.NET, adding a & before a = meant "append to the end of the variable". I just converted this from some C# code, so it may not be entirely accurate. :(

Reedbeta
05-03-2006, 04:54 PM
Well, in C#, that does a bitwise AND of the left-hand-side with the right-hand-side and assigns it to the lhs. I don't know if &= has a meaning in VB, but what you probably want is 'newFlags = newFlags Or CreateFlags.PureDevice'. That will set the PureDevice bit within the newFlags bitfield.

.oisyn
05-03-2006, 05:06 PM
In VB, the & operator is used to concatenate strings. Don't know if they also work for enum-like types, but it seems to compile anyway :).

cypher543
05-04-2006, 11:42 AM
I changed it to:
newFlags = newFlags Or CreateFlags.PureDevice
Everything compiles now, but I just get a window with the image of whatever is behind it burned into the form. :( I have a render loop that is supposed the clear the screen to green.
Public Sub Render()
d3dDevice.Clear(ClearFlags.Target & ClearFlags.ZBuffer, Color.FromArgb(255, 0, 255, 0), 1.0F, 0)
d3dDevice.BeginScene()

' Render stuff here

d3dDevice.EndScene()
d3dDevice.Present()
End Sub
Then, Render() is called from the form's paint event.

Jare
05-04-2006, 12:49 PM
Use the Debug runtime and see what errors it reports.

Mjolnir
05-04-2006, 01:20 PM
ClearFlags.Target & ClearFlags.ZBuffer
ClearFlags.Target Or ClearFlags.ZBuffer :sneaky: ?

cypher543
05-04-2006, 03:10 PM
Jare: It doesn't give me any errors...
Mjolnir: Well, that fixed it. Should have figured that out... oh well. Thanks!