From 30567e086ce09301726e391f0de49339427fa45d Mon Sep 17 00:00:00 2001 From: Recrown Date: Sat, 11 Aug 2018 16:15:47 -0500 Subject: [PATCH] proper disposal issue fixed; error while screen is not paused but not renrendering (ex. dragging window) fixed; --- .../zero1hd/rhythmbullet/RhythmBullet.java | 4 ++-- .../desktop/audio/PCMObtainer.java | 19 ++++++++----------- .../desktop/graphics/ui/pages/Page.java | 11 ++++++----- .../desktop/screens/main/MainScreen.java | 1 + 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/core/src/zero1hd/rhythmbullet/RhythmBullet.java b/core/src/zero1hd/rhythmbullet/RhythmBullet.java index a9496f2..7275884 100755 --- a/core/src/zero1hd/rhythmbullet/RhythmBullet.java +++ b/core/src/zero1hd/rhythmbullet/RhythmBullet.java @@ -193,13 +193,13 @@ public class RhythmBullet extends Game { public void dispose() { Gdx.app.debug("Core", "disposing..."); try { + getScreen().dispose(); skinAtlas.dispose(); getSkin().dispose(); assetManager.dispose(); - getScreen().dispose(); assetPack.dispose(); } catch (NullPointerException npe) { - //Means the game was closed before everything was initiated. + Gdx.app.debug("Core", "Disposal error occurred, possibly caused by failing to complete initialization.", npe); } super.dispose(); } diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/audio/PCMObtainer.java b/desktop/src/zero1hd/rhythmbullet/desktop/audio/PCMObtainer.java index ee5558c..f836f08 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/audio/PCMObtainer.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/audio/PCMObtainer.java @@ -113,8 +113,11 @@ public class PCMObtainer implements Observer, PCMSystem { } private void synchronizeBufferWithPlayback() { - playingBuffer.position(calcBufferPosition()); - windowsRead = (int) ((mc.getCurrentPosition() * sampleRate) / windowSize); + int bufferPos = calcBufferPosition(); + if (bufferPos <= playingBuffer.limit()) { + playingBuffer.position(calcBufferPosition()); + windowsRead = (int) ((mc.getCurrentPosition() * sampleRate) / windowSize); + } } private void setMusic() { @@ -152,15 +155,13 @@ public class PCMObtainer implements Observer, PCMSystem { public int getWindowSize() { return windowSize; } - + private class BufferStreamReadThread implements Runnable { private String name = "PCM-Audio-Processing"; private Thread thread; private volatile boolean run = true; private long timeOfLastRead; private long waitTime; - private int syncC, normC; - private float syncPercentage; @Override public void run() { while (run) { @@ -184,13 +185,8 @@ public class PCMObtainer implements Observer, PCMSystem { } if (windowsRead != currentPlaybackWindow) { synchronizeBufferWithPlayback(); - syncC++; - } else { - normC++; } - syncPercentage = (syncC*100)/(float)(normC+syncC); - System.out.printf("%.2f", syncPercentage); - System.out.print("%\n"); + //wait for a bit before reading again depending on the speed at which the system does playback. waitTime = Math.max(0, millisPerWindow - TimeUtils.timeSinceMillis(timeOfLastRead)); try { @@ -213,6 +209,7 @@ public class PCMObtainer implements Observer, PCMSystem { public void start() { if (thread == null) { thread = new Thread(this, name); + thread.setDaemon(true); thread.start(); } else { synchronized (this) { diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/pages/Page.java b/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/pages/Page.java index 7400e03..dbc8515 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/pages/Page.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/pages/Page.java @@ -35,10 +35,11 @@ public class Page extends Group implements Disposable { @Override public void setStage(Stage stage) { - if (stage == null && !hasParent()) { - dispose(); - } - if (!(stage.getViewport() instanceof ScreenViewport)) { + if (stage == null) { + if (!hasParent()) { + dispose(); + } + } else if (!(stage.getViewport() instanceof ScreenViewport)) { throw new IllegalArgumentException("Pages are explicitly for GUIs, and thus should have a 1:1 ratio between pixel and texture size for maximum clarity. This means that the stage should be using a ScreenViewport."); } super.setStage(stage); @@ -60,7 +61,7 @@ public class Page extends Group implements Disposable { } super.setParent(parent); } - + @Override public void dispose() { Gdx.app.debug(getClass().getSimpleName(), "Disposing..."); diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainScreen.java b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainScreen.java index 570deb8..6692bdd 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainScreen.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainScreen.java @@ -149,6 +149,7 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen { } }); + stage.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) {