App state problem

I’m having a problem with app states. When attaching or detaching app states from anywhere other than my main class’ simpleInitApp() method, I get strange and unexplainable behavior. For example, when detaching a state, the state’s loop stops, but action listeners, particles, post processing effects etc. still run in the next state. Also, when attaching a new state, I get lag, objects start with odd translations, lag, and game logic seems to be going unplayably “fast forward”. It all works as expected when done from the simpleInitApp() method though, so I know the app states are working. Any ideas?

You apparently expect the AppState to detach all Spatials you attach in its initialize method or something, this isn’t true, you have to do it in cleanup(). I guess most of your issues are due to similar preconceptions.

Are you attaching/detaching from outside the render thread?

@zarch said:
Are you attaching/detaching from outside the render thread?


Note: that is perfectly fine... as long as one understands that initialize() and cleanup() are going to be called on the render thread.

To the OP, I think we will need more information. There is nothing about app states themselves that will cause the problems you describe.

Edit: given the description so far, attaching the same state over and over again could also lead to this behavior, for example. So if you've add a state 50 times without detaching it then you will get update() called 50 times per frame.

Whoops! Sorry for such a noobish question. I wasn’t clearly understanding the function of the cleanup() method. Got it now. Thanks for the help!