Hello Forum I'm learning more about Form Apps in VB.net and I encountered the error 'System.ObjectDisposedException', no matter what I do this error doesn't seem to want to stop. This error occurs in two stages all under the declaration of BBGO which is declared as graphics. This should be the relevent code:
Private Sub DrawGraphics()
'FILL THE BACKBUFFER
For X = 0 To 38
For Y = 0 To 28
GetSourceRect(X, Y, TileSize, TileSize)
DRect = New Rectangle(X * TileSize, Y * TileSize, TileSize, TileSize)
GO.DrawImage(Wall, DRect, SRect, GraphicsUnit.Pixel)
GO.DrawRectangle(Pens.Red, mouseX * TileSize, mouseY * TileSize, TileSize, TileSize)
GO.DrawImage(BMPToon, XPos * TileSize * MoveSpeed, YPos * TileSize * MoveSpeed, SRect, GraphicsUnit.Pixel)
'DRAW FINAL LAYERS
'GUYS, MENUS, ETC
GO.DrawString("Controls: " & vbCrLf & _
"W = Up" & vbCrLf & _
"S = Down" & vbCrLf & _
"A = Left" & vbCrLf & _
"D = Right" & vbCrLf & _
"Space = Stop" & vbCrLf & _
"", Me.Font, Brushes.Red, 625, 0)
'COPY BACKBUFFER TO GRAPHICS OBJECT
GO = Graphics.FromImage(BB)
'DRAW BACK BUFFER TO SCREEN
***BBGO = Me.CreateGraphics
BBGO.DrawImage(BB, 0, 0, ResWidth, ResHeight)***
There is alot more code to this form but I dont want to go over board with it all if you guys need more of the code or any help I'll give it to you but in the mean time I'm going to keep pounding at this error.
It's at draw back buffer to screen and occurs when I close the application. The actual code it points to is BBGO = Me.CreateGraphics. I am using the Try Catch method to solve the problem and it seems to be working. Perhaps not the best way to make a game app.
Yeah the line of code that was triggering the error was BBGO = Me.Create Graphics and I used: Try BBGO. Me.CreateGraphics BBGO.DrawImage(BB, 0, 0, ResWidth, ResHeight) Catch End End Try To catch it and if it does catch it it ends the whole class...which is kind of what I wanted to do when I exited the program, There were also a few other errors i had to catch because they were not being disposed and I had to dispose of them myself and catch the error if they tried to run after they were disposed. Sorry for causing such a fuss.
I bet there is a better way to make 2D games without XNA but I'll get there eventually.