Fixed error handling issues in the game container. (#218)

This makes error catching generally more robust. Catch all exceptions in start() loop, catch close_sub() exceptions separately, and suppress linked errors (so the root exception should actually get captured).

Also fixed null pointers in methods called by close_sub().

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2016-12-20 12:08:41 -05:00
parent 59204665bc
commit 8b7b7e0354
3 changed files with 20 additions and 14 deletions

View File

@ -38,8 +38,8 @@ import org.newdawn.slick.opengl.InternalTextureLoader;
* AppGameContainer extension that sends critical errors to ErrorHandler. * AppGameContainer extension that sends critical errors to ErrorHandler.
*/ */
public class Container extends AppGameContainer { public class Container extends AppGameContainer {
/** SlickException causing game failure. */ /** Exception causing game failure. */
protected SlickException e = null; protected Exception e = null;
/** /**
* Create a new container wrapping a game * Create a new container wrapping a game
@ -72,16 +72,24 @@ public class Container extends AppGameContainer {
getDelta(); getDelta();
while (running()) while (running())
gameLoop(); gameLoop();
} finally { } catch (Exception e) {
// destroy the game container this.e = e;
close_sub(); }
destroy();
// report any critical errors // destroy the game container
if (e != null) { try {
ErrorHandler.error(null, e, true); close_sub();
e = null; } catch (Exception e) {
} if (this.e == null) // suppress if caused by a previous exception
this.e = e;
}
destroy();
// report any critical errors
if (e != null) {
ErrorHandler.error(null, e, true);
e = null;
forceExit = true;
} }
if (forceExit) { if (forceExit) {

View File

@ -623,7 +623,7 @@ public enum GameImage {
* If the default image has already been loaded, this will do nothing. * If the default image has already been loaded, this will do nothing.
*/ */
public void setDefaultImage() { public void setDefaultImage() {
if (defaultImage != null || defaultImages != null) if (defaultImage != null || defaultImages != null || Options.getSkin() == null)
return; return;
// try to load multiple images // try to load multiple images

View File

@ -281,8 +281,6 @@ public class Cursor {
// reset angles // reset angles
cursorAngle = 0f; cursorAngle = 0f;
GameImage.CURSOR.getImage().setRotation(0f);
GameImage.CURSOR_TRAIL.getImage().setRotation(0f);
} }
/** /**