Hi.
As the title says, I've started to get an "unhandled exception" error when I EXIT my game, never while playing, to be specific:
"Unhandled exception at 0x698ba051 in NTI-Zombie_Survival.exe: 0xC0000005: Access violation reading location 0x00000008."
That.
What I know, is that it has something to do with an array of 120 slots, that I fill up with pointers to objects - as this is a game, where 120 zombies (in this case) is pretty overkill to start with, I only loop through the first 10 slots when I initialize the game.
My loop for adding the first 10 zombies:
1 2
|
for(int i = 0; i < 10; i++)
zombie[i] = new Zombie(zombieTexture);
|
And I also loop through the whole array before and NULL all slots.
And to add more zombies when necessery:
1 2 3 4 5 6 7 8 9
|
if(iKillCounter == iKillsMoreZombies && iNrOfZombies + 3 < 120)
{
for(int i = iNrOfZombies; i < iNrOfZombies + 3; i++)
{
zombie[i] = new Zombie(zombieTexture);
}
iNrOfZombies += 3;
iKillsMoreZombies *= 1.35;
}
|
And to delete:
1 2 3 4 5 6 7 8
|
for(int i = 0; i < iNrOfZombies; i++)
{
if(zombie[i] != NULL)
{
delete zombie[i];
zombie[i] = NULL;
}
}
|
If I use:
delete [] zombie;
to delete the array, I get another error:
http://bayimg.com/pAomhAAdE
I'm using SFML for all the graphics and input handling and such, if that makes any difference.
So, any ideas on how to solve this?
Tell me if there is anything more you need to know, at least I think I've included everything that's important.
Thanks in advance.