• Create Account

### #Actualjohnmarinelli

Posted 17 January 2013 - 06:49 PM

Hi everyone,

So I have a class called c_Zombie.  I also have a class called c_AIstates, which is an FSM for the zombie's AI.

In my zombie class, I create a pointer of type c_AIstate:

(pseudocode)

class c_Zombie
{
private:
c_AIstate *currentAIstate;

public:
...
}

it also has a pointer to the animation class as well.  many of my entity classes contain pointers to their various "components".

my question is: why do I get errors when I delete my pointers in the Zombie destructor?

c_Zombie::~c_Zombie(void)
{
delete currentAIstate;
currentAIstate = NULL;

delete onAnimate;
onAnimate = NULL;
}


I'm sure that I should know the answer but I dont

also,

assuming that i actually SHOULDN'T be explicitly deleting the pointers in the Zombie's dctor, how does the memory get deleted?  or should it not be deleted at all?

EDIT: okay, the program is working now - however, I know with certainty that the same issue arises if I delete an SDL_Surface* in the dstructor, and/or an onAnimate* in some other classes.

Thanks for your time!

### #2johnmarinelli

Posted 17 January 2013 - 06:45 PM

Hi everyone,

So I have a class called c_Zombie.  I also have a class called c_AIstates, which is an FSM for the zombie's AI.

In my zombie class, I create a pointer of type c_AIstate:

(pseudocode)

class c_Zombie
{
private:
c_AIstate *currentAIstate;

public:
...
}

it also has a pointer to the animation class as well.  many of my entity classes contain pointers to their various "components".

my question is: why do I get errors when I delete my pointers in the Zombie destructor?

/*i get 0xfeeefeee when i use this*/
c_Zombie::~c_Zombie(void)
{
delete currentAIstate;
currentAIstate = NULL;

delete onAnimate;
onAnimate = NULL;
}


I'm sure that I should know the answer but I dont

also,

assuming that i actually SHOULDN'T be explicitly deleting the pointers in the Zombie's dctor, how does the memory get deleted?  or should it not be deleted at all?

Thanks for your time!

### #1johnmarinelli

Posted 17 January 2013 - 06:44 PM

Hi everyone,

So I have a class called c_Zombie.  I also have a class called c_AIstates, which is an FSM for the zombie's AI.

In my zombie class, I create a pointer of type c_AIstate:

(pseudocode)

class c_Zombie
{
private:
c_AIstate *currentAIstate;

public:
...
}

it also has a pointer to the animation class as well.  many of my entity classes contain pointers to their various "components".

my question is: why do I get errors when I delete my pointers in the Zombie destructor?  It doesn't even happen when the zombie is 'deleted' (say a player enters a building; the zombie gets deleted and therefore the destructor should be called) - it happens at initialization.

/*i get 0xfeeefeee when i use this*/
c_Zombie::~c_Zombie(void)
{
delete currentAIstate;
currentAIstate = NULL;

delete onAnimate;
onAnimate = NULL;
}


I'm sure that I should know the answer but I dont

also,

assuming that i actually SHOULDN'T be explicitly deleting the pointers in the Zombie's dctor, how does the memory get deleted?  or should it not be deleted at all?

Thanks for your time!

PARTNERS