From 8b7b7e03542208c265a2593ddbb9a20b4b4119ad Mon Sep 17 00:00:00 2001 From: Jeffrey Han Date: Tue, 20 Dec 2016 12:08:41 -0500 Subject: [PATCH] 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 --- src/itdelatrisu/opsu/Container.java | 30 ++++++++++++++++++----------- src/itdelatrisu/opsu/GameImage.java | 2 +- src/itdelatrisu/opsu/ui/Cursor.java | 2 -- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/itdelatrisu/opsu/Container.java b/src/itdelatrisu/opsu/Container.java index 1a2b96d4..6f146985 100644 --- a/src/itdelatrisu/opsu/Container.java +++ b/src/itdelatrisu/opsu/Container.java @@ -38,8 +38,8 @@ import org.newdawn.slick.opengl.InternalTextureLoader; * AppGameContainer extension that sends critical errors to ErrorHandler. */ public class Container extends AppGameContainer { - /** SlickException causing game failure. */ - protected SlickException e = null; + /** Exception causing game failure. */ + protected Exception e = null; /** * Create a new container wrapping a game @@ -72,16 +72,24 @@ public class Container extends AppGameContainer { getDelta(); while (running()) gameLoop(); - } finally { - // destroy the game container - close_sub(); - destroy(); + } catch (Exception e) { + this.e = e; + } - // report any critical errors - if (e != null) { - ErrorHandler.error(null, e, true); - e = null; - } + // destroy the game container + try { + close_sub(); + } 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) { diff --git a/src/itdelatrisu/opsu/GameImage.java b/src/itdelatrisu/opsu/GameImage.java index 51b93ab7..b3d7e4d6 100644 --- a/src/itdelatrisu/opsu/GameImage.java +++ b/src/itdelatrisu/opsu/GameImage.java @@ -623,7 +623,7 @@ public enum GameImage { * If the default image has already been loaded, this will do nothing. */ public void setDefaultImage() { - if (defaultImage != null || defaultImages != null) + if (defaultImage != null || defaultImages != null || Options.getSkin() == null) return; // try to load multiple images diff --git a/src/itdelatrisu/opsu/ui/Cursor.java b/src/itdelatrisu/opsu/ui/Cursor.java index d0382aae..49b7d73d 100644 --- a/src/itdelatrisu/opsu/ui/Cursor.java +++ b/src/itdelatrisu/opsu/ui/Cursor.java @@ -281,8 +281,6 @@ public class Cursor { // reset angles cursorAngle = 0f; - GameImage.CURSOR.getImage().setRotation(0f); - GameImage.CURSOR_TRAIL.getImage().setRotation(0f); } /**