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() {
//tell the actor thread to finish, then wait for it to complete any actions it may be doing.
if (actorThread != null && actorThread.isAlive()){
synchronized (GameScene.class){
synchronized (actorThread) {
actorThread.interrupt();
}
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);
}
}
}
if (!waitForActorThread( 4500 )){
Throwable t = new Throwable();
t.setStackTrace(actorThread.getStackTrace());
throw new RuntimeException("timeout waiting for actor thread! ", t);
}
Emitter.freezeEmitters = false;
@ -567,10 +553,28 @@ public class GameScene extends PixelScene {
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
public synchronized void onPause() {
try {
waitForActorThread(500);
Dungeon.saveAll();
Badges.saveGlobal();
Journal.saveGlobal();

View File

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