From a02613bb7644c8849230e2246312456d3970722a Mon Sep 17 00:00:00 2001 From: yugecin Date: Wed, 18 Jan 2017 19:22:14 +0100 Subject: [PATCH] pause music on exception --- src/yugecin/opsudance/OpsuDance.java | 3 +++ .../opsudance/core/DisplayContainer.java | 22 +++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/yugecin/opsudance/OpsuDance.java b/src/yugecin/opsudance/OpsuDance.java index 42fa75de..06a2f206 100644 --- a/src/yugecin/opsudance/OpsuDance.java +++ b/src/yugecin/opsudance/OpsuDance.java @@ -69,6 +69,7 @@ public class OpsuDance { } while (rungame()); + container.teardownAL(); closeSingleInstanceSocket(); DBController.closeConnections(); @@ -78,6 +79,7 @@ public class OpsuDance { private boolean rungame() { try { container.setup(); + container.resume(); } catch (Exception e) { ErrorHandler.error("could not initialize GL", e).preventContinue().show(); return false; @@ -89,6 +91,7 @@ public class OpsuDance { caughtException = e; } container.teardown(); + container.pause(); return caughtException != null && ErrorHandler.error("update/render error", caughtException).show().shouldIgnoreAndContinue(); } diff --git a/src/yugecin/opsudance/core/DisplayContainer.java b/src/yugecin/opsudance/core/DisplayContainer.java index 82b39997..ee8912d7 100644 --- a/src/yugecin/opsudance/core/DisplayContainer.java +++ b/src/yugecin/opsudance/core/DisplayContainer.java @@ -19,8 +19,8 @@ package yugecin.opsudance.core; import itdelatrisu.opsu.GameImage; import itdelatrisu.opsu.Options; +import itdelatrisu.opsu.audio.MusicController; import itdelatrisu.opsu.ui.Fonts; -import org.lwjgl.LWJGLException; import org.lwjgl.Sys; import org.lwjgl.openal.AL; import org.lwjgl.opengl.Display; @@ -95,6 +95,8 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen private long lastFrame; + private boolean wasMusicPlaying; + private String glVersion; private String glVendor; @@ -150,7 +152,7 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen } - public void run() throws LWJGLException { + public void run() throws Exception { while(!exitRequested && !(Display.isCloseRequested() && state.onCloseRequest())) { delta = getDelta(); @@ -211,9 +213,25 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen public void teardown() { Display.destroy(); + } + + public void teardownAL() { AL.destroy(); } + public void pause() { + wasMusicPlaying = MusicController.isPlaying(); + if (wasMusicPlaying) { + MusicController.pause(); + } + } + + public void resume() { + if (wasMusicPlaying) { + MusicController.resume(); + } + } + public void setDisplayMode(int width, int height, boolean fullscreen) throws Exception { if (this.width == width && this.height == height) { Display.setFullscreen(fullscreen);