 |
 |

05-18-2006, 05:04 PM
|
 |
Centurion
|
|
Join Date: Nov 2004
Location: Texas
Posts: 165
|
|
Application crashing when I close
|
I have a really annoying problem that the application SOMETIMES (not always) crashes when I close it. Here is my New() Sub for my main form:
Code:
Public Sub New()
MyBase.New()
MyBase.Size = New Size(600, 600)
Me.Show()
bRunning = InitD3D()
Do While bRunning
Render()
Application.DoEvents()
Loop
CleanUp()
End
End Sub
' Cleanup active DirectX objects
Public Sub CleanUp()
If Not Nothing Is Sphere Then Sphere = Nothing
If Not Nothing Is graphicsFont Then graphicsFont = Nothing
If Not Nothing Is Camera Then Camera = Nothing
If Not Nothing Is device Then device = Nothing
End Sub
bRunning is set to False if the Esc key is pressed. I'll step through it in the Debuger and it will exit the game loop, go through CleanUp(), get to End, and crash. I've tried different things, such as commenting out the call to CleanUp() which made it only crash sometimes, and commenting out the End so that it would just finish the Sub. When I did the latter, I added a MyBase.Close call whenever Esc was hit so that it would close. That caused it to crash when the Sub ended. The error messages are as follows:
If I try to end it with the End command, I get:
Code:
An unhandled exception of type 'System.NullReferenceException' occurred in microsoft.directx.direct3dx.dll
Additional information: Object reference not set to an instance of an object.
If I remove the End and let it kill itself, I get:
Code:
An unhandled exception of type 'System.ObjectDisposedException' occurred in system.windows.forms.dll
Additional information: Cannot access a disposed object named "Form1".
Any ideas what the problem is?
|
__________________
"The whole trouble comes from the fact that there is so much tinkering with software. It is not made in a clean fabrication process, which it should be. What we need, is software engineering." — F.L. Bauer, 1968
|

05-21-2006, 06:12 AM
|
 |
MetaCenturion
Retired Moderator * Guru *
|
|
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
|
|
|
Ending the program when you create an object is not very wise. You should have a subroutine (Main) create the object and then run some initialization routine. When your routine is finished running, the routine should end and the Sub Main should close your class.
|
|

05-21-2006, 09:12 PM
|
 |
Centurion
|
|
Join Date: Nov 2004
Location: Texas
Posts: 165
|
|
|
Isn't that what's happening when I comment out the End command? The New() sub is pretty much like Main() for a form, only it doesn't close after New() finishes (which is why I threw the End in there)
|
__________________
"The whole trouble comes from the fact that there is so much tinkering with software. It is not made in a clean fabrication process, which it should be. What we need, is software engineering." — F.L. Bauer, 1968
|

05-21-2006, 09:20 PM
|
 |
Joseph Koss
* Guru *
|
|
Join Date: Aug 2003
Location: Unfashionable End
Posts: 3,615
|
|
|
Does .NET really support this sort of stuff inside a constructor?
While I am not an OO expert, it seems to me that heavy work inside a constructor used to be frowned upon in a major way.
|
|

05-22-2006, 04:03 PM
|
 |
Centurion
|
|
Join Date: Nov 2004
Location: Texas
Posts: 165
|
|
You may be right. I must have modified something in my original copy of the tutorials and ended up using my constructor as my Main().  I'll try fixing that. Thanx.
|
__________________
"The whole trouble comes from the fact that there is so much tinkering with software. It is not made in a clean fabrication process, which it should be. What we need, is software engineering." — F.L. Bauer, 1968
|

05-22-2006, 04:08 PM
|
 |
MetaCenturion
Retired Moderator * Guru *
|
|
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
|
|
Definitely. I have not seen any good reason to be destroying any objects inside of a constructor. Especially if it is the constructor to your startup form...
If you startup with a startup form, you have an invisible set of calls that occur after the form is constructed... most notably, the form is shown (making a form appear is more than setting it to a new form). If you close it after it is constructed, the next call to show the form (that you won't see) will fail. 
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|