Archived

This topic is now archived and is closed to further replies.

Null pointer HELL

This topic is 5048 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites