Null pointer HELL

Started by
5 comments, last by Ademan555 20 years, 1 month ago
Ok, i have a class CONTROLLED_PLAYER it contains two sprites that i defined (which are jsut wrappers around the ID3DXSprite) and anyways, its constructor simply ZeroMemory()s the whole class, then, the load function looks like this

bool CONTROLLED_PLAYER::Load(char * FilePath, LPDIRECT3DDEVICE9 pDev, TEXPOOL * Pool)
{
		if ((pDev != NULL)&& (Pool != NULL))
		{
			if (!(CONTROLLED_PLAYER::Top.Load(".\\Debug\\Resources\\Bitmaps\\DEFAULTTop.bmp", pDev, Pool)))
					return FALSE;
			if (!(CONTROLLED_PLAYER::Legs.Load(".\\Debug\\Resources\\Animations\\DEFAULTLegs.anim", pDev, Pool)))
					return FALSE;
		}
		else
		{
			#ifndef __RELEASE___
				if (!pDev)
					OutputDebugString("pDev is NULL\n");

				if (!Pool)
					OutputDebugString("Pool is NULL\n");
			#endif
		}
	}
}
and then in the WinMain

CONTROLLED_PLAYER pl;
pl.Load(NULL, Game.GetDevice(), &Pool);
now... if i was to do the same exact thing, except outside of the class, it works fine, (WinMain)

ROTATE /*same as in class*/ Top;
Top.Load(".\\Debug\\Resources\\Bitmaps\\DEFAULTTop.bmp", Game.GetDevice() /*LPDIRECT3DDEVICE9*/, &Pool/*TEXTURE MANAGER POINTER*/);
but as it is it says "trying to acess 0x00000000 which SHOULDnt happen, because i explicitly check for the Pool and pDev being NULL...
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
Advertisement
You should use your debugger to find out exactly which pointer is null, and backtrack the call stack to find out *why* it is null.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
You will have to track the line where the error happens. Maybe Game.GetDevice() causes the problem. If you are not allowing NULL pointers, maybe you should be using references instead of pointers.

Also, you can''t ZeroMemory() your objects. The reason is that the NULL pointer doesn''t necesary consist of zeros. Usually it does, but there are platforms where your code will break. You are using directX, so your code isn''t portable anyway, but it''s something to have in mind.
Don''t ZeroMemory classes. You run the risk of clobbering the vtable.

This is a "sit there with the debugger until you find it"-type problem that isn''t conducive to message boards, anyway.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
i think antareus has it actually... in fact ill bet thats it, oh btw the debugger wouldnt let me look at my variables... cuz when it came down from fullscreen d3d it just kinda crashes, whether its because of a breakpoint or a bad pointer
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
in the debugger is _vfptr a pointer to the vtable? cuz if so at least i know wut my problem is, though i dont know where that happened...
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
quote:Original post by Ademan555
in the debugger is _vfptr a pointer to the vtable? cuz if so at least i know wut my problem is, though i dont know where that happened...


Sounds very likely, yes.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement