[Solved (seemingly)]Nifty interaction focus issue


Here’s the deal:

I have an applet.

I have a gui consisting of several screens. I use [java]goToScreen(String screen)[/java] to switch between them.

One of the screens is used as a “selector” for which “world node” to attach. This node is attached to the root node when the user clicks “ok”, at which point the nifty screens are switched as well and the ui replaced. The new gui consists of a row of buttons sitting on top of the “world”.

When running it through jMP things usually work out fine, but sometimes (1-2 times out of 10) and always when testing a deployed applet, nifty loses focus and can not be interacted with (no button clicks, or hover effects).

When i didn’t attach the world node, it works fine, even when deployed (at least the number of times i tried it). The node is of course fairly large since it contains quite alot of elements, but it’s pre generated and only attached at this point in time.

I’ve also tried alternating the attachment point to before or after i change nifty screens, and there might be a higher chance of failure if i attach it just before switching screens.

I’ve tried sleeping the thread, i’ve pondered about threading the attachment (but this would probably upset the main thread). I’m basically out of ideas for now.

I’ve seen some threads where nifty is drawn outside the frustrum, but this is not that issue, as the gui is visible at all times.

Any ideas?


As i expected, it’s some kind of “focus race” issue.

It might seem like it’s a pretty implementation specific problem, but here’s an explanation on how to solve it:

Create an object for delayed execution and a loading state.

Do immediately:

Switch to loading state/screen

Attach world node.

Do later:

Switch to in game state/ui.

This also has the benefit of a better user experience since they don’t get any choppy performance as the node is attached (they’re looking at a beautiful loading screen)


Thank you Rickard, i must admit that my knowledge of nifty is pretty basic, and I’m sorry that I can’t answer this kind of question.

But your determination and constant feedback (not only on nifty) is invaluable for the community.

Thank you

Thanks nehon.

Unfortunately, it’s not a 100% proof solution. Since it seems to be dependent on how long it takes to add the node, i sometimes still lose nifty interaction.