Hey guys,
So I'm using a finite state machine for AI in my game. Up until recently it has been working perfectly - however, yesterday, for no discernable reason, this piece of code says that the currentAIstate's vfptr is inaccessible right when the instance of c_Zombie spawns:
void c_Zombie::logic( Uint32 deltaTicks )
{
currentAIstate->AIlogic(collisionBox, c_Entity_manager::getPlayer()->getBox(), xVel, yVel, up, down, left, right, alerted);
/*some other code..*/
if(condition){
setnextAIstate(someState);
}
changeAIState(currentAIstate);
}
the code for switching AI states goes like this:
void changeAIState(c_AIstate* currentAIstate)
{
if ( nextAIState != AI_NULL )
{
delete currentAIstate;
switch (nextAIState)
{
case CHILL:
currentAIstate = new c_Chillmode(); break;
case GO_TO:
currentAIstate = new c_Gotomode(); break;
case ATTACK:
currentAIstate = new c_Attackmode(); break;
case DEAD:
currentAIstate = new c_Deadmode(); break;
}
AIstateID = nextAIState;
nextAIState = AI_NULL;
}
}
void setnextAIState( int state )
{
if ( state != DEAD )
{
nextAIState = state;
}
else
nextAIState = DEAD;
}
I can't figure out why it just decided to stop working recently;
also, I read that allocating memory during runtime is a bad idea - what other options do I have for changing AI states, assuming that the method I'm using right now is a bad idea?
here's a link to the github if you need more info: https://github.com/johnmarinelli/8bit-sh/tree/master/cpp
or, just leave a comment with whatever info you need; I've already had to delete one feature of the game because of this, and I don't want to have to do it again.
Thanks for your time!