void256/nifty-gui — pull request #155 by 3xp0n3nt (2013-10-24 12:22:28+00:00)
Title: Fix NullPointerException in Nifty class.

The Bug: If Nifty.exit() is called more than once in a row, or if the
current Screen is an instance of NullScreen when Nifty.exit() is called,
then a NullPointerException is thrown in the current Screen's
endScreenMethod, specifically when it tries to call
Nifty.resetMouseInputEvents() on a null instance of Nifty within the
resetLayers() method, since the Nifty instance will be null if the
current Screen is an instance of NullScreen.

The scenario above specifically occurs when exiting from the
AllExamplesMain example demo from nifty-examples when running the
example from nifty-examples-libgdx. When the "Exit" menu choice is
clicked in the menu scrollPanel, and the button labeled "yes" is
clicked, Nifty.exit() is called, but the main application window itself
stays open. The NullPointerException described above occurs when closing
the main application window because that in turn calls
LibgdxExampleApplication.dispose(), which in turn calls Nifty.exit(),
like it should because it can't assume that Nifty.exit() has already
been called.

The Fix: Don't call the endScreen method in Nifty.exit() if the current
Screen is null, i.e., and instance of NullScreen. In fact, since
Nifty.exit() is designed to only ever be called once, and since it
should really be idempotent since that increases robustness, simply
return immediately from Nifty.exit() if the current Screen is null.
Since the first invocation of Nifty.exit() will always make the current
screen an instance of NullScreen, this is effectively the same as
returning immediately if Nifty.exit() has already been called.