Title basically says it all. I’m trying to detach AppStateMyHud that have all the Nifty Code inside and I can’t. I tried putting nifty.exit() in cleanup method but it doesn’t help either… Gui is still there (and still updating as it has a Label that tracks my mouse position).
How do I completely close Nifty GUI along with appstate in which it resides?
Not detaching was my mistake after all. I forgot super.initialize statement in my appstate init method.
But now detaching and exiting gives me (even though it works):
WARNING: An event service by the name NiftyEventBusalready exists. Perhaps multiple threads tried to create a service about the same time?
org.bushe.swing.event.EventServiceExistsException: An event service by the name NiftyEventBusalready exists. Perhaps multiple threads tried to create a service about the same time?
Why is that? I thought nifty.exit() destroys the instance completely so there shouldn’t be any service existing…
Yeah but I want to be able to kill Nifty completely or at least detach it completely. If I did then there shouldn’t be trouble creating new one right?
Or should I just change my init method to include something like: if niftydisplay exists add it to view port if niftydisplay doesn't exist create new one and add it to view port
…and accept the fact that this sonofagui is unkillable? And if so, how do I do that?
And most importantly - how do I check if nifty instance exists?
I want to be able to detach my appstate completely with everything that this appstate created (in this case nifty) so there’s no trace of it left anywhere (except for some trash left for garbage collector to take care of).
If it was just the screen I’d just change nifty screen I have now to empty nifty screen.
Well this will not be possible… you cannot exit nifty completely. You have to use the specific instance of nifty after the init process. Easiest way is to use different screens as bloodwalker mentioned.
Solved the issue: it wasn’t related to creating nifty per se, but to creating appstate in which nifty resides. In the end right solution (and probably the only one) to switch appstate with nifty on/off is either:
Check if appstate already exists instead of forcing creation and relying on the fact that second “same” appstate overrides previous (kind-of-a-singleton),
Force garbage collector after detaching appstate, so whatever is left of nifty (and there is a lot) is utterly destroyed the moment appstate is detached.
I chose the first solution because forcing garbage collector is kinda slow.