proper disposal issue fixed; error while screen is not paused but not

renrendering (ex. dragging window) fixed;
This commit is contained in:
Harrison Deng 2018-08-11 16:15:47 -05:00
parent f2a60ea490
commit 30567e086c
4 changed files with 17 additions and 18 deletions

View File

@ -193,13 +193,13 @@ public class RhythmBullet extends Game {
public void dispose() { public void dispose() {
Gdx.app.debug("Core", "disposing..."); Gdx.app.debug("Core", "disposing...");
try { try {
getScreen().dispose();
skinAtlas.dispose(); skinAtlas.dispose();
getSkin().dispose(); getSkin().dispose();
assetManager.dispose(); assetManager.dispose();
getScreen().dispose();
assetPack.dispose(); assetPack.dispose();
} catch (NullPointerException npe) { } 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(); super.dispose();
} }

View File

@ -113,9 +113,12 @@ public class PCMObtainer implements Observer, PCMSystem {
} }
private void synchronizeBufferWithPlayback() { private void synchronizeBufferWithPlayback() {
int bufferPos = calcBufferPosition();
if (bufferPos <= playingBuffer.limit()) {
playingBuffer.position(calcBufferPosition()); playingBuffer.position(calcBufferPosition());
windowsRead = (int) ((mc.getCurrentPosition() * sampleRate) / windowSize); windowsRead = (int) ((mc.getCurrentPosition() * sampleRate) / windowSize);
} }
}
private void setMusic() { private void setMusic() {
Gdx.app.debug("PCMObtainer", "music set."); Gdx.app.debug("PCMObtainer", "music set.");
@ -159,8 +162,6 @@ public class PCMObtainer implements Observer, PCMSystem {
private volatile boolean run = true; private volatile boolean run = true;
private long timeOfLastRead; private long timeOfLastRead;
private long waitTime; private long waitTime;
private int syncC, normC;
private float syncPercentage;
@Override @Override
public void run() { public void run() {
while (run) { while (run) {
@ -184,13 +185,8 @@ public class PCMObtainer implements Observer, PCMSystem {
} }
if (windowsRead != currentPlaybackWindow) { if (windowsRead != currentPlaybackWindow) {
synchronizeBufferWithPlayback(); 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. //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)); waitTime = Math.max(0, millisPerWindow - TimeUtils.timeSinceMillis(timeOfLastRead));
try { try {
@ -213,6 +209,7 @@ public class PCMObtainer implements Observer, PCMSystem {
public void start() { public void start() {
if (thread == null) { if (thread == null) {
thread = new Thread(this, name); thread = new Thread(this, name);
thread.setDaemon(true);
thread.start(); thread.start();
} else { } else {
synchronized (this) { synchronized (this) {

View File

@ -35,10 +35,11 @@ public class Page extends Group implements Disposable {
@Override @Override
public void setStage(Stage stage) { public void setStage(Stage stage) {
if (stage == null && !hasParent()) { if (stage == null) {
if (!hasParent()) {
dispose(); dispose();
} }
if (!(stage.getViewport() instanceof ScreenViewport)) { } 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."); 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); super.setStage(stage);

View File

@ -149,6 +149,7 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
} }
}); });
stage.addListener(new ClickListener() { stage.addListener(new ClickListener() {
@Override @Override
public void clicked(InputEvent event, float x, float y) { public void clicked(InputEvent event, float x, float y) {