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());
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();
}

View File

@ -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);