Error in My Visual Basic 2005 code

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
Fallental
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 43
Joined: Mon Mar 02, 2009 6:13 pm

Error in My Visual Basic 2005 code

Post by Fallental »

Ok so the rundown. Im new to programming, figured i would start with visual basic and pick up some books about it, made a few simples apps then i found a book called Visual Basic Game Programming for Teens Second Edition By Jonathan Harbour http://www.jharbour.com/forum

So im on Chapter 4- Sprites/animating sprites/ stuff like that ive learned how to load bitmaps and have made many tests BUT They wont run
! i get this when i try to run them.


I have written everything in the source code correctly for the previous applications made in the book but whenever i try to run them i get
the error message "Unhandled exception has occured in your application. If You click continue, the application will ignore this error and attempt to continue. If you click Quit, the application will close immediatly. Error in the application." i click on details and i get:

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
Error in the application.
-2005530516 (D3DERR_INVALIDCALL)
at Microsoft.DirectX.Direct3D.Device..ctor(Int32 adapter, DeviceType deviceType, Control renderWindow, CreateFlags behaviorFlags, PresentParameters[] presentationParameters)
at LoadBitMap.Form1.Form1_Load(Object sender, EventArgs e) in C:\Documents and Settings\Tristan\My Documents\Visual Studio 2005\Projects\LoadBitMap\LoadBitMap\Form1.vb:line 43
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
LoadBitMap
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Documents%20and%20Settings/Tristan/My%20Documents/Visual%20Studio%202005/Projects/LoadBitMap/LoadBitMap/bin/Debug/LoadBitMap.exe
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 8.0.0.0
Win32 Version: 8.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Runtime.Remoting
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
Microsoft.DirectX.Direct3D
Assembly Version: 1.0.2902.0
Win32 Version: 9.05.132.0000
CodeBase: file:///C:/WINDOWS/assembly/GAC/Microsoft.DirectX.Direct3D/1.0.2902.0__31bf3856ad364e35/Microsoft.DirectX.Direct3D.dll
----------------------------------------
Microsoft.DirectX.Direct3DX
Assembly Version: 1.0.2909.0
Win32 Version: 9.10.455.0000
CodeBase: file:///C:/WINDOWS/assembly/GAC/Microsoft.DirectX.Direct3DX/1.0.2909.0__31bf3856ad364e35/Microsoft.DirectX.Direct3DX.dll
----------------------------------------
Microsoft.DirectX
Assembly Version: 1.0.2902.0
Win32 Version: 5.04.00.2904
CodeBase: file:///C:/WINDOWS/assembly/GAC/Microsoft.DirectX/1.0.2902.0__31bf3856ad364e35/Microsoft.DirectX.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

And so i looked in my code for the bug.

Check This out....

Im just gonna use some of the code for loading a bitmap (happens with all applications tho)

i click debug....

and get this!

! InvalidCallException Was Unhandled. Error in the application.

and it highlights this line of code in yellow

REM create the direct3d device
device = New Device(adapternumber, DeviceType.Hardware, Me, flags, params)

Idk wat the problem is im pretty sure i wrote it write...

Full code here:

Imports Microsoft.DirectX
Imports Microsoft.DirectX.direct3d
Public Class Form1
REM define some useful constants
Const SCREENW As Integer = 800
Const SCREENH As Integer = 600

Dim black As Integer = RGB(0, 0, 0)

REM Direct3D device variable
Dim device As Direct3D.Device

REM create image from a Direct3D surface
Dim image As Direct3D.Surface
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
REM resize the form
Me.Size = New Size(SCREENW, SCREENH)
Me.Text = "Bitmap Loading Demo"
Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.Opaque, True)

REM get the desktop display mode
Dim adapternumber As Integer = Manager.Adapters.Default.Adapter
Dim mode As DisplayMode
mode = Manager.Adapters.Default.CurrentDisplayMode

REM set up the presentation parameters
Dim params As New PresentParameters
params.Windowed = True
params.SwapEffect = SwapEffect.Copy
params.AutoDepthStencilFormat = DepthFormat.D16
params.EnableAutoDepthStencil = True
params.MultiSample = MultiSampleType.None
params.BackBufferCount = 1
params.BackBufferWidth = SCREENW
params.BackBufferHeight = SCREENH

REM check video card capailities
Dim flags As CreateFlags
flags = CreateFlags.HardwareVertexProcessing
flags += CreateFlags.PureDevice

REM create the direct3d device
device = New Device(adapternumber, DeviceType.Hardware, Me, flags, params)

REM load the bitmap file
image = device.CreateOffscreenPlainSurface(SCREENW, SCREENH, Format.A8R8G8B8, Pool.Default)
SurfaceLoader.FromFile(image, "sky.bmp", Filter.None, black)
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
REM begin rendering
device.BeginScene()

REM clear the back buffer
device.Clear(ClearFlags.Target + ClearFlags.ZBuffer, Color.Green, 1.0, 0)

REM specify the drawing rectangles for the image
Dim source_rect As New System.Drawing.Rectangle(0, 0, SCREENW, SCREENH)
Dim dest_rect As New System.Drawing.Rectangle(0, 0, SCREENW, SCREENH)

REM get reference to the back buffer
Dim backbuffer As Direct3D.Surface
backbuffer = device.GetBackBuffer(0, 0, BackBufferType.Mono)

REM draw the image
device.StretchRectangle(image, source_rect, backbuffer, dest_rect, 0)

REM stop rendering
device.EndScene()

REM copy back buffer to the screen
device.Present()
End Sub
Private Sub form1_keydown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
REM chck key code for ESC key
If e.KeyCode = Keys.Escape Then
REM destroy the direct3d device
device.Dispose()

REM end the program
End
End If
End Sub

End Class

(if you wondering yes i did add all of the references for direct3d and directx!)

My video Card is also not outdated!
Help please!
Thanks
Fallental

Read more about my problem http://www.jharbour.com/forum
Go to the board index -> go to category Game Dev -> Click Visual Basic -> and look for this post -> Visual basic Game programming for teen 2nd edition HELP!!!!
User avatar
trufun202
Game Developer
Game Developer
Posts: 1105
Joined: Sun Sep 21, 2008 12:27 am
Location: Dallas, TX
Contact:

Re: Error in My Visual Basic 2005 code

Post by trufun202 »

I googled "2005530516 (D3DERR_INVALIDCALL)"

and found this
d3derr_invalidcall "-2005530516" - SOLVED

This past weekend I was getting a steady diet of the above errors. Tracing out the program told me that as soon as we passed vertices to the graphics device it would die miserably. It took me a while but I finally chased it down to the fact that I had neglected to define the vertice types as follows:

Game.devices.Graphics.VertexFormat = CustomVertex.PositionColored.Format;

I'm sure all the gurus around here already knew that :) but I thought I might share. Maybe oneday this will help someone.
Good luck!
-Chris

YouTube | Twitter | Rad Raygun

“REAL ARTISTS SHIP” - Steve Jobs
Fallental
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 43
Joined: Mon Mar 02, 2009 6:13 pm

Re: Error in My Visual Basic 2005 code

Post by Fallental »

If you could (since im such a newbie) Copy my above code and reply to this but add that new line of script in like red so i know were it goes in script? if you could it would be greatly appreciated!
(i subbed to you on youtube cool vids! :)
)
Thanks fallental
User avatar
trufun202
Game Developer
Game Developer
Posts: 1105
Joined: Sun Sep 21, 2008 12:27 am
Location: Dallas, TX
Contact:

Re: Error in My Visual Basic 2005 code

Post by trufun202 »

I'm honestly not sure where it needs to go or what namespaces you need to include for that to compile. I've never done any Direct3D development... However, its definitely somewhere above line 43, which is where it's blowing up.

Perhaps its one of the params that you pass into the Device constructor:

Code: Select all

device = New Device(adapternumber, DeviceType.Hardware, Me, flags, params)
Thanks for subscribing. ;)
-Chris

YouTube | Twitter | Rad Raygun

“REAL ARTISTS SHIP” - Steve Jobs
Fallental
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 43
Joined: Mon Mar 02, 2009 6:13 pm

Re: Error in My Visual Basic 2005 code

Post by Fallental »

Hmmm ok thanks alot tho you helped a heap=D
i just need to know where i put that line....
Fallental
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 43
Joined: Mon Mar 02, 2009 6:13 pm

Re: Error in My Visual Basic 2005 code

Post by Fallental »

I really need help anyone else going to post????
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Error in My Visual Basic 2005 code

Post by MarauderIIC »

That line is already in your code, he's saying. Check it for errors.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Error in My Visual Basic 2005 code

Post by dandymcgee »

I've never done anything with Direct3D in visual basic either (I'm not sure why you would want to use such a powerful library in such a terrible language <-- just my opinion).

I know it would definitely help me to be able to read and understand your code if you used tags though.

I can only tell you to try the same thing trufun did, google your errors. That's the only way I've ever been able to get anything at all done in visual basic since the help files are impossibly useless. Sorry I wasn't of much assistance, hopefully you can figure it out.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
Post Reply