pause music on exception

This commit is contained in:
yugecin 2017-01-18 19:22:14 +01:00
parent c03897a47d
commit a02613bb76
2 changed files with 23 additions and 2 deletions

View File

@ -69,6 +69,7 @@ public class OpsuDance {
} }
while (rungame()); while (rungame());
container.teardownAL();
closeSingleInstanceSocket(); closeSingleInstanceSocket();
DBController.closeConnections(); DBController.closeConnections();
@ -78,6 +79,7 @@ public class OpsuDance {
private boolean rungame() { private boolean rungame() {
try { try {
container.setup(); container.setup();
container.resume();
} catch (Exception e) { } catch (Exception e) {
ErrorHandler.error("could not initialize GL", e).preventContinue().show(); ErrorHandler.error("could not initialize GL", e).preventContinue().show();
return false; return false;
@ -89,6 +91,7 @@ public class OpsuDance {
caughtException = e; caughtException = e;
} }
container.teardown(); container.teardown();
container.pause();
return caughtException != null && ErrorHandler.error("update/render error", caughtException).show().shouldIgnoreAndContinue(); return caughtException != null && ErrorHandler.error("update/render error", caughtException).show().shouldIgnoreAndContinue();
} }

View File

@ -19,8 +19,8 @@ package yugecin.opsudance.core;
import itdelatrisu.opsu.GameImage; import itdelatrisu.opsu.GameImage;
import itdelatrisu.opsu.Options; import itdelatrisu.opsu.Options;
import itdelatrisu.opsu.audio.MusicController;
import itdelatrisu.opsu.ui.Fonts; import itdelatrisu.opsu.ui.Fonts;
import org.lwjgl.LWJGLException;
import org.lwjgl.Sys; import org.lwjgl.Sys;
import org.lwjgl.openal.AL; import org.lwjgl.openal.AL;
import org.lwjgl.opengl.Display; import org.lwjgl.opengl.Display;
@ -95,6 +95,8 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
private long lastFrame; private long lastFrame;
private boolean wasMusicPlaying;
private String glVersion; private String glVersion;
private String glVendor; 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())) { while(!exitRequested && !(Display.isCloseRequested() && state.onCloseRequest())) {
delta = getDelta(); delta = getDelta();
@ -211,9 +213,25 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
public void teardown() { public void teardown() {
Display.destroy(); Display.destroy();
}
public void teardownAL() {
AL.destroy(); 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 { public void setDisplayMode(int width, int height, boolean fullscreen) throws Exception {
if (this.width == width && this.height == height) { if (this.width == width && this.height == height) {
Display.setFullscreen(fullscreen); Display.setFullscreen(fullscreen);