Access violation writing location 0x00000000

Hi all, I'm back with another question.

In my (DarkGDK) game I keep getting the "access violation writing location 0x00000000" error. I've searched for information about this error and it seems it has to do with accessing a NULL pointer, which obviously explains the 0x00000000 address.

Visual C++ 2008 keeps pointing at the second line of
1
2
void SetCollisionType(colltype colNewCollisionType)
	{colCollisionType = colNewCollisionType;}

after the error accurs, but I don't see how that is relevant, there are no pointers in that part. Does this mean I should look elsewhere in my code, or is it something in that 'function' that I don't understand?
Can you write definition of colltype ? How did you define it ?
Last edited on
Firstly, try commenting this line. If the error remains, you have to look somewhere else.
Is SetCollisionType a method? If so, could it be that it is at some point called from a pointer that is null?
The colltype enumeration:

1
2
3
4
5
6
7
enum colltype
{
	UNDEFINED,
	IMPASSABLE,
	PASSABLE,
	SPECIAL
};


SetCollisionType is a member of class CTile, the constructor of the class is

1
2
3
4
5
CTile::CTile()
{
	colCollisionType = UNDEFINED;
	strImageName = "";
}

so colCollisionType already has a value.
What I meant was that there is probably somewhere a piece of code like this:
1
2
3
CTile* ptr;
//lots of code
ptr->SetCollisionType(/*...*/);//and ptr == 0 at this point 
Oh hamsterman, I'm sorry I missed your post so I replied to Dufresne's post.
If I'm right, the pointer isn't 0, I set it to 0 when constructing the class it belongs to though, is that wrong? Because right after that I give it another value:

1
2
3
CTile* tTileTypeArray = new (std::nothrow) CTile [iSize];

CTile* ptTileTypeArray = tTileTypeArray;


And I test ptTileTypeArray, so if it's 0 it won't even try to call SetCollisionType.
Last edited on
In that function you are implicitly using this-> access colCollisionType inside your class.

Your this is probably NULL (as has been said), so I suggest you put a breakpoint before that section and see if you can find out when exactly your class is becoming a NULL pointer.
My god, I can't believe it. I didn't realize there was "CTile*" in front of "ptTileTypeArray". "ptTileTypeArray" already exists outside that function and I meant to use that one, because that's the one calling the members of CTile. But, because I copied (btw totally unnessecary) the address of tTileTypeArray to the local ptTileTypeArray, the member-calling ptTileTypeArray was still NULL.

Thanks anyway for the help, now let's see if I can fix the next couple of run-time errors.
Last edited on
Topic archived. No new replies allowed.