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

View File

@ -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() {
@ -159,8 +162,6 @@ public class PCMObtainer implements Observer, PCMSystem {
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) {

View File

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

View File

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