StateManager problem

Hello



I have:

[java]public static void main(String[] args) {

Main app = new Main();

app.initApp();

}



public void initApp() {



initAppStates();



}



private void initAppStates() {

sCabin = new appstateCabin();

stateManager.attach(sCabin);

sCabin.initialize(stateManager, this);

sCabin.prepareState();



sSectorMap = new appstateSectorMap();

stateManager.attach(sSectorMap);

sSectorMap.initialize(stateManager, this);

sSectorMap.prepareState();

}

[/java]



Do you have any idea why in the end stateManager only have one state attached to it (sector state)? The weirdest thing is that if I first attach the sector map state, and then cabin state, state manager will have 2 states attached to it.

Just based on what is provided, my guess would be that sSectorMap detaches sCabin during initialize or prepareState.



But I actually have no idea what’s going on for sure because you are manually calling initialize on your states and have an odd-ish prepareState() method. I’m not sure why you aren’t letting state manager call initialize for you (it’s going to anyway).

But I actually have no idea what’s going on for sure because you are manually calling initialize on your states..

You tell that I do not need to call initialize method by myself?

..and have an odd-ish prepareState() method. I’m not sure why you aren’t letting state manager call initialize for you (it’s going to anyway).

There's nothing particular in them. I just disabled them for testing right now, and the result remains the same.

Here's the code of sCabin initialize method
[java]@Override
public void initialize(AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);
//TODO: initialize your AppState, e.g. attach spatials to rootNode
//this is called on the OpenGL thread after the AppState has been attached
log.log("Cabin:Init --");
this.appRef = (Main)app;
//this.stateManagerRef = stateManager;
im = appRef.getInputManager();

cam = appRef.getCamera();
initialUpVec = cam.getUp().clone();

this.setDragToRotate(true);
}[/java]

and here the sSectorMap state's initialization:
[java]@Override
public void initialize(AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);
//TODO: initialize your AppState, e.g. attach spatials to rootNode
//this is called on the OpenGL thread after the AppState has been attached
log.log("SectorMap: state init--");
this.appRef = (Main)app;
this.stateManagerRef = stateManager;
im = appRef.getInputManager();

cam = appRef.getCamera();
initialUpVec = Vector3f.UNIT_X.clone();

this.setDragToRotate(true);
}[/java]

So, as you can see there's no code that could mess with stateManager. This problem is my headache for 2 days already... :(

StateManager calls initialize.



But maybe since you are extending Application directly you’re not updating state manager properly? (in which case lots of things will be broken)



This is another issue with not extending SimpleAppliction. I have to request so much code just to figure out what’s happening.



And because I hate to make assumptions, when you say:

“Do you have any idea why in the end stateManager only have one state attached to it (sector state)?”



How are you determining that? Where are you checking?

But maybe since you are extending Application directly you’re not updating state manager properly? (in which case lots of things will be broken)

Well, I have copied update method directly from SimpleApplication class, sooo, I believe it couldn't be the case..

How are you determining that? Where are you checking?

Yes, of course, I do logging and set some breakpoints.. and by not seeing on the screen what I suppose to see :)
The idea of is to init all states, which in my case I have 2, and in the end set one of them as enabled.. but I cannot do so because stateManager have only one of them attached to it, and I just cannot understand why..

I’d like to see the code that tries to access your states. The stuff that fails to find the state if the order is switched.



StateManager isn’t doing anything magic, really. (This all presumes you are running the latest stable update otherwise state manager is very buggy.) When you attach a state, it is added to a list of pending states. On the next update pass, it’s initialize() method is called and it is moved to the “active states” list. Either way, attempting to look up the state will succeed… whether it’s in the pending list or not.



StateManager calls initialize even if the state is disabled. You should be able to add a disabled state or enabled state… it doesn’t really matter. initialize will still be called. Enabled only controls whether the state’s update and render methods are called.