I keep getting this error and I can't figure out why. This error is saying this error for member variable mpCurrentState and mInitialStateID. These variables are part of class StateMachine. I set them in the StateMachine constructor to NULL for mpCurrentState and -1 for minitialStateID, yet by the time the update function is hit they have nothing. I cout in the constructor and they are initialized, but something happens to make them unreadable and I can't figure out what.
//state machine class
class StateMachine :public Trackable
{
public:
StateMachine();
~StateMachine(){};
void addState(StateMachineState* pState);
void setInitialStateID(const SM_idType& id){ std::cout << "state set\n"; mInitialStateID = id; };
void update();//give the current state a chance to run
void start();//go to the initial state
protected:
void transitionToState(const SM_idType& targetID);//call onExit for old state and onEntrance for the new state
std::map<SM_idType, StateMachineState*> mStates;//all states indexed by stateID
StateMachineState* mpCurrentState;//the current state that is running
SM_idType mInitialStateID;//the id of the state which should run first
};
I print the pointer with a null value to make sure it is a null value and not garbage. Any who, a friend found my problem. A silly mistake. I was put a type before the state machine's variable when I was initializing it so it wasn't using the state machine member variable in the class that was using it. whoops.
1 2 3 4
//this was the mistake
StateMachine* mpStateMachine = new StateMachine();
1 2 3 4
//this is what it should have been
mpStateMachine = new StateMachine();