v0.6.0a: improved threading logic when gamescene is destroyed
This commit is contained in:
parent
3b689da833
commit
0697268a73
|
@ -28,6 +28,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Statistics;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||
import com.watabou.utils.Bundlable;
|
||||
import com.watabou.utils.Bundle;
|
||||
|
||||
|
@ -224,7 +225,11 @@ public abstract class Actor implements Bundlable {
|
|||
|
||||
if (!doNext){
|
||||
interrupted = false;
|
||||
|
||||
synchronized (Thread.currentThread()) {
|
||||
synchronized (GameScene.class){
|
||||
GameScene.class.notify();
|
||||
}
|
||||
try {
|
||||
Thread.currentThread().wait();
|
||||
} catch (InterruptedException e) {
|
||||
|
|
|
@ -414,17 +414,34 @@ public class GameScene extends PixelScene {
|
|||
|
||||
public void destroy() {
|
||||
|
||||
freezeEmitters = false;
|
||||
|
||||
scene = null;
|
||||
Badges.saveGlobal();
|
||||
|
||||
//tell the actor thread to finish, then wait for it to complete any actions it may be doing.
|
||||
if (actorThread.isAlive()){
|
||||
synchronized (actorThread) {
|
||||
actorThread.interrupt();
|
||||
}
|
||||
synchronized (GameScene.class){
|
||||
if (actorThread.getState() != Thread.State.WAITING) {
|
||||
try {
|
||||
GameScene.class.wait(5000);
|
||||
} catch (InterruptedException e) {
|
||||
ShatteredPixelDungeon.reportException(e);
|
||||
}
|
||||
synchronized (actorThread) {
|
||||
if (actorThread.getState() != Thread.State.WAITING) {
|
||||
Throwable t = new Throwable();
|
||||
t.setStackTrace(actorThread.getStackTrace());
|
||||
throw new RuntimeException("timeout waiting for actor thread! ", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
freezeEmitters = false;
|
||||
|
||||
scene = null;
|
||||
Badges.saveGlobal();
|
||||
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user