unexpected behavior with std list and pointers

Started by
2 comments, last by freeworld 11 years, 4 months ago
This is from my phone please excuse the grammar.

I've got a very simple state machine that stores states as pointers in a std list. States have a isAlive flag that tells the statemachine that the state needs to be deleted. I always only ever operate on the back of he list which should always be the newest state. When I say a state is added. The machine adds the state after the current state is fully processed including deleting of it.

So far my game flows like so. Menu state is added. Runs. A level loader state gets added and his states adds a level state. When the level is lost it flags it self as dead and adds a gameover state. The game Hoover state flags itself as dead and the stack is cleared back down to the level loader state. Which has no more levels to load so flags itself as dead. Now all other states get deleted properly but for some reason when it reaches the check to see if the load level state is dead it just skips it. And he debugger clearly shows the state as dead even the code that sets it as dead runs right.

It's a lot of separate code else I would've posted it. I'm just really stumped on this one. Why it won't delete this state but all the great get cleaned up just fine.
[ dev journal ]
[ current projects' videos ]
[ Zolo Project ]
I'm not mean, I just like to get to the point.
Advertisement
you were too detailed about abstraction of your project, but did not provide technical point of problem. Could you state again where is your problem? A pointer in std::list still remains in list, or it does not "delete" in other abstract manner? You sad you operate at the end of the list only, but you perform some 'marking' magic on the members on as to free them, I would think about that. make sure you are removing std::list members, or marking them in order to be "deleted" in your pattern, and wheather this marking magic corellates with your std::list 'at the end operate' idea. Are you cutting of states from the first state that is ended all to way to the back of the list or how? Cannot get it, sorry. You should describe your problem more accurately to get better help. I am just stabbing in the dark.
Pare your code down to the simplest example that demonstrates your problem, and post that example here (if in doing this, you don't figure it out on your own, anyway; often this is a good way of finding bugs yourself). Without code to look at, we're all just like JohnnyCode, stabbing in the dark.
got it, i redefined the isAlive member in the derived class. it's always somthing so simple that takes so long to find.
[ dev journal ]
[ current projects' videos ]
[ Zolo Project ]
I'm not mean, I just like to get to the point.

This topic is closed to new replies.

Advertisement