Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 Direct3D n00bness...
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Vankwysha
Squire

Australia
43 Posts

Posted - Jun 15 2005 :  01:49:52 AM  Show Profile  Click to see Vankwysha's MSN Messenger address  Reply with Quote
I'm a total Direct3D n00b, and due to the small number of tutorials that I've been able to find on using D3D to draw 2D graphics, I'm posting yet again.

I've followed all of the tutorials to the letter, and D3D initialises fine, and I can even display a sprite, but when I try to exit the program, I get a NullReferenceException. I can't figure out why!!! I've used stubs, flags, debug output lines, made sure that I dispose of everything and it still doesn't work!!! GRRRR!!!! So, anyway, I've uploaded my source code and if anyone can tell me what the blatantly obvious problem that I'm sure is right under my nose is I would be very grateful. This is not really a major problem I know, but I think it would be incredibly sloppy to leave my engine like this, especially as I plan to DLL it and use it again.

Download Attachment: Engine Source Code.txt
5.55 KB

ardman
Squire

15 Posts

Posted - Jun 15 2005 :  02:25:39 AM  Show Profile  Visit ardman's Homepage  Reply with Quote
I think that your problem is in your Do Loop. At the end of it you are using Frm.Ending. Change this to:

Loop Until Ending

You've set your variable Ending in the form key press. This should help. If not, it's because your dispose a form whilst it's still shown. You don't need to do this.


Cheers! :)
Go to Top of Page

Vankwysha
Squire

Australia
43 Posts

Posted - Jun 15 2005 :  04:33:27 AM  Show Profile  Click to see Vankwysha's MSN Messenger address  Reply with Quote
The reason that I have to use Frm.Ending is because sub Main is shared. Because I put sub main in the form class, and main is meant to execute before the form exists, it is effectively outside the form, so I have to refer to the Ending variable as Frm.Ending, as it is within the frmMain namespace. I've tried basically every combination of Frm.Dispose, Frm.Close, End and just about every other "ending" procedure that I know of to no end.
Go to Top of Page

ardman
Squire

15 Posts

Posted - Jun 15 2005 :  08:26:43 AM  Show Profile  Visit ardman's Homepage  Reply with Quote
Ok, in that case, just use End and the application will close.

Another possibility is to use:

  
Do While frm.Created  
  
      ' Rendering bits  
  
Loop
  
GCard = nothing  
End
  
  


but dont dispose the form as it will close at the end of the application.

Cheers! :)

Edited by - ardman on Jun 15 2005 08:29:02 AM
Go to Top of Page

Vankwysha
Squire

Australia
43 Posts

Posted - Jun 15 2005 :  5:19:00 PM  Show Profile  Click to see Vankwysha's MSN Messenger address  Reply with Quote
I've tried that, but when I use End, not only does it not quit but it doesn't actually do anything. I press escape and it just freezes. Something weird did happen though; I tried moving my sub main into a separate module. When I did, the program worked once absolutely fine and then stopped working. I'm wondering if this has something to do with the memory or the way directx stores its sprites....
Go to Top of Page

Vankwysha
Squire

Australia
43 Posts

Posted - Jun 16 2005 :  11:14:51 PM  Show Profile  Click to see Vankwysha's MSN Messenger address  Reply with Quote
Ok, I wasn't confused before, I'm confused now.

While I was attempting to fix my code, I became angry and frustrated, and inserted the following lines at the end of the render loop:

  
Debug.WriteLine(“spolug”)  
Debug.WriteLine(“ITS NOT FIAR”) ‘when you’re full of rage it’s hard to spell correctly  
  


When I entered this code, the program started working perfectly!!! I can’t understand how this could possibly have any effect on the function of the program. Any thoughts?

EDIT:

The program has sinced ceased to work .

Edited by - Vankwysha on Jun 16 2005 11:17:05 PM
Go to Top of Page

Lachlan87
Moderator

USA
160 Posts

Posted - Jun 17 2005 :  07:06:49 AM  Show Profile  Reply with Quote
Sorry I took so long to get around to replying. . .

I used to have a similar problem. Here's how I do it now. Instead of using "Loop Until Frm.Ending" try using a while loop like this
While frm.Created  'This is built-in. You don't have to make the frm.Created Variable yourself.  
                'Do stuff  
            End While


When you want to kill your application, just use Me.Close. Me.Close won't totally get rid of your window, but it will cause the built-in frm.Created to = false, so you'll still need to call frm.Dispose after your loop exits.

Let me know if this works for you!

Go to Top of Page

Vankwysha
Squire

Australia
43 Posts

Posted - Jun 17 2005 :  08:47:35 AM  Show Profile  Click to see Vankwysha's MSN Messenger address  Reply with Quote
I tried that, and it worked a couple of times, but now it's stacked. I'm wondering if there's something wrong with my D3D dll or something. I'll try downloading the SDK again.
Go to Top of Page

Threshold
Squire

USA
44 Posts

Posted - Jun 17 2005 :  2:38:42 PM  Show Profile  Reply with Quote
Why don't you just use the standard "running" flag for your main class? Set it to true when everything initializes correctly and then loop until it's false. When exiting simply set it to false. Also, I'm not sure if it's the same with VB.NET, but in VB6, using "End" is not a smart idea as it doesn't terminate classes.

Life is short. They say "don't waste it, have fun." They're right, don't waste it...but DO redefine "fun."
Go to Top of Page

Vankwysha
Squire

Australia
43 Posts

Posted - Jun 21 2005 :  8:36:04 PM  Show Profile  Click to see Vankwysha's MSN Messenger address  Reply with Quote
I've managed to achieve functionality in windowed mode by using a flag in the render sub, however, it does not seem to apply in full screen. I have managed to isolate the error, in case it helps:

  
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.  
   at Microsoft.DirectX.Direct3D.Sprite.OnLostDevice()  
   at Microsoft.DirectX.Direct3D.Sprite.OnParentLost(Object sender, EventArgs e)  
   at Microsoft.DirectX.Direct3D.Device.raise_DeviceLost(Object i1, EventArgs i2)  
   at Microsoft.DirectX.Direct3D.Device.Finalize()The program '[488] Graphics Engine.exe' has exited with code 0 (0x0).  
  
Go to Top of Page

Vankwysha
Squire

Australia
43 Posts

Posted - Jun 21 2005 :  8:42:36 PM  Show Profile  Click to see Vankwysha's MSN Messenger address  Reply with Quote
I've moved and adjusted my use of the Dispose() methods of my various devices, and it appears to be fully functional. However, I don't wish to raise my hopes to soon. If it keeps working, thank you all for your help.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 0.12 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.