Unregistering ScreenControllers

Here is my use case:

I load up nifty and use nifty.fromXml(“first.xml”, “myScreen”, ControllerA, ControllerB);

This would be for the main menu.

When the user gets into the game, new XML is loaded, nifty.fromXml(“second.xml”, “myScreen”, ControllerC, ControllerD)

Nifty removes the screens as expected and loads in the new ones.



Now the problem arises if I head back to the main menu and re-load the ‘first.xml’ config, the controllers are just appended to the list of ‘registeredScreenControllers’ in Nifty.java, and the old ones never seem to get removed. Now it doesn’t look like this collection is actually used except to look up names, so it probably isn’t the issue. I tried unsubscribing the screens and annotations from the controllers, but it still seems to hang onto them

If I need to I could keep some singletons of the controllers, but this could become troublesome when I allow parts of the game to be modded and multiple mods get combined.



Any idea how I can get around this, or am I missing something while unregistering screens?

Update to more recent Nifty. This has been double-fixed :slight_smile:



(I did two separate patches - one adds an “unregisterScreenControllers” method, the other switches storage into a mapping so new ones for the same class replace old ones).

3 Likes

ah ok, good to hear :slight_smile:

awesome, i think void said nifty 1.3.2 is being released soon, so hopefully gets integrated soon after :slight_smile: