Application crashing when I close
Application crashing when I close
Application crashing when I close
Application crashing when I close
Application crashing when I close
Application crashing when I close Application crashing when I close Application crashing when I close Application crashing when I close Application crashing when I close Application crashing when I close Application crashing when I close Application crashing when I close
Application crashing when I close Application crashing when I close
Application crashing when I close
Go Back  Xtreme Visual Basic Talk > > > > Application crashing when I close


Reply
 
Thread Tools Display Modes
  #1  
Old 05-18-2006, 06:04 PM
Moohasha's Avatar
Moohasha Moohasha is offline
Centurion
 
Join Date: Nov 2004
Location: Texas
Posts: 165
Default 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
Reply With Quote
  #2  
Old 05-21-2006, 07:12 AM
Iceplug's Avatar
IceplugApplication crashing when I close Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

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.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #3  
Old 05-21-2006, 10:12 PM
Moohasha's Avatar
Moohasha Moohasha is offline
Centurion
 
Join Date: Nov 2004
Location: Texas
Posts: 165
Default

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
Reply With Quote
  #4  
Old 05-21-2006, 10:20 PM
Rockoon's Avatar
Rockoon Rockoon is offline
Joseph Koss

* Guru *
 
Join Date: Aug 2003
Location: Unfashionable End
Posts: 3,615
Default

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.
Reply With Quote
  #5  
Old 05-22-2006, 05:03 PM
Moohasha's Avatar
Moohasha Moohasha is offline
Centurion
 
Join Date: Nov 2004
Location: Texas
Posts: 165
Default

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
Reply With Quote
  #6  
Old 05-22-2006, 05:08 PM
Iceplug's Avatar
IceplugApplication crashing when I close Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

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.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Application crashing when I close
Application crashing when I close
Application crashing when I close Application crashing when I close
Application crashing when I close
Application crashing when I close
Application crashing when I close Application crashing when I close Application crashing when I close Application crashing when I close Application crashing when I close Application crashing when I close Application crashing when I close
Application crashing when I close
Application crashing when I close
 
Application crashing when I close
Application crashing when I close
 
-->