CompositeAppState enabling

I would expect a CompositeAppState to enable and disable the child appstates. The code below should do:

onEnable Appstate1
onEnable Appstate2
onDisable Appstate1
onDisable Appstate2

then hang indefinitely.

Instead I have

onEnable Appstate1
onEnable Appstate2

and only when I exit

onDisable Appstate1
onDisable Appstate2

Is this a bug or a misunderstanding on my part?

public class DoubleAppState extends CompositeAppState {

    public DoubleAppState() {
        super(
                new AppState1(),
                new AppState2());
    }

    protected void initialize(Application app) {
        setEnabled(false);
    }
}

class AppState1 extends BaseAppState {

    @Override
    protected void initialize(Application app) {
    }

    @Override
    protected void cleanup(Application app) {
    }

    @Override
    protected void onEnable() {
        System.out.println("onEnable Appstate1");
    }

    @Override
    protected void onDisable() {
        System.out.println("onDisable Appstate1");
    }
}

class AppState2 extends BaseAppState {

    @Override
    protected void initialize(Application app) {
    }

    @Override
    protected void cleanup(Application app) {
    }

    @Override
    protected void onEnable() {
        System.out.println("onEnable Appstate2");
    }

    @Override
    protected void onDisable() {
        System.out.println("onDisable Appstate2");
    }
}

I think if you added a debug line to your initialize() you would see that it’s run before the other app states maybe.

Anyway, why do this? Why not just disable composite app state from the start and never enable the children just to disable them again?

Maybe my code is unnecessarily convoluted, however I have a few appstate dependencies that I solved with disabling…

Nope. I got:

init 1
onEnable Appstate1
init 2
onEnable Appstate2
init DoubleAppState
DoubleAppState disabled
// hangs here. Appstate 1 and 2 are not disabled until I close the application
onDisable Appstate1
onDisable Appstate2

So, while it’s probably true that I should try to rearrange my code, the setEnabled() on CompositeAppState don’t disable the children when called on init()

But that’s an extremely strange thing to do.

I’d need to know more about why you want all of your child states to immediately enable then disable again to be able to tell you how to do it in a good way, though.

It all started when I noticed an hiccup on game start (due to attaching of appstates and assets loading), so I init() everything and just enable them when needed. However as I said I need to rearrange stuff, and if there’s still issues I’ll come back here. :slight_smile: