v0.9.2: added various safety checks to reduce the chance of crashes

This commit is contained in:
Evan Debenham 2021-01-26 18:23:44 -05:00
parent 3afc33d48d
commit 778fafbcdd
2 changed files with 31 additions and 25 deletions

View File

@ -532,24 +532,10 @@ public class GameScene extends PixelScene {
public void destroy() { public void destroy() {
//tell the actor thread to finish, then wait for it to complete any actions it may be doing. //tell the actor thread to finish, then wait for it to complete any actions it may be doing.
if (actorThread != null && actorThread.isAlive()){ if (!waitForActorThread( 4500 )){
synchronized (GameScene.class){ Throwable t = new Throwable();
synchronized (actorThread) { t.setStackTrace(actorThread.getStackTrace());
actorThread.interrupt(); throw new RuntimeException("timeout waiting for actor thread! ", t);
}
try {
GameScene.class.wait(5000);
} catch (InterruptedException e) {
ShatteredPixelDungeon.reportException(e);
}
synchronized (actorThread) {
if (Actor.processing()) {
Throwable t = new Throwable();
t.setStackTrace(actorThread.getStackTrace());
throw new RuntimeException("timeout waiting for actor thread! ", t);
}
}
}
} }
Emitter.freezeEmitters = false; Emitter.freezeEmitters = false;
@ -567,10 +553,28 @@ public class GameScene extends PixelScene {
actorThread.interrupt(); actorThread.interrupt();
} }
} }
public synchronized boolean waitForActorThread(int msToWait ){
if (actorThread != null && actorThread.isAlive()){
return true;
}
synchronized (actorThread) {
actorThread.interrupt();
}
try {
GameScene.class.wait(msToWait);
} catch (InterruptedException e) {
ShatteredPixelDungeon.reportException(e);
}
synchronized (actorThread) {
return Actor.processing();
}
}
@Override @Override
public synchronized void onPause() { public synchronized void onPause() {
try { try {
waitForActorThread(500);
Dungeon.saveAll(); Dungeon.saveAll();
Badges.saveGlobal(); Badges.saveGlobal();
Journal.saveGlobal(); Journal.saveGlobal();

View File

@ -50,13 +50,15 @@ public class AttackIndicator extends Tag {
public AttackIndicator() { public AttackIndicator() {
super( DangerIndicator.COLOR ); super( DangerIndicator.COLOR );
instance = this; synchronized (this) {
lastTarget = null; instance = this;
lastTarget = null;
setSize( 24, 24 );
visible( false ); setSize(24, 24);
enable( false ); visible(false);
enable(false);
}
} }
@Override @Override