Error in My Visual Basic 2005 code
Posted: Mon Mar 02, 2009 6:38 pm
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!!!!
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!!!!