Note: You must be registered in order to post a reply.
|
Vankwysha |
Posted - Jun 15 2005 : 01:49:52 AM 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 |
Vankwysha |
Posted - Jun 21 2005 : 8:42:36 PM 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. |
Vankwysha |
Posted - Jun 21 2005 : 8:36:04 PM 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
|
Threshold |
Posted - Jun 17 2005 : 2:38:42 PM 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. |
Vankwysha |
Posted - Jun 17 2005 : 08:47:35 AM 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. |
Lachlan87 |
Posted - Jun 17 2005 : 07:06:49 AM 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 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! |
Vankwysha |
Posted - Jun 16 2005 : 11:14:51 PM 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 . |
Vankwysha |
Posted - Jun 15 2005 : 5:19:00 PM 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.... |
ardman |
Posted - Jun 15 2005 : 08:26:43 AM Ok, in that case, just use End and the application will close.
Another possibility is to use:
Do While frm.Created Loop GCard = nothing End
but dont dispose the form as it will close at the end of the application. |
Vankwysha |
Posted - Jun 15 2005 : 04:33:27 AM 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. |
ardman |
Posted - Jun 15 2005 : 02:25:39 AM 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. |
|
|
VBGamer |
© |
|
|
|
|