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.blobs.Blob;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||||
import com.watabou.utils.Bundlable;
|
import com.watabou.utils.Bundlable;
|
||||||
import com.watabou.utils.Bundle;
|
import com.watabou.utils.Bundle;
|
||||||
|
|
||||||
|
@ -224,7 +225,11 @@ public abstract class Actor implements Bundlable {
|
||||||
|
|
||||||
if (!doNext){
|
if (!doNext){
|
||||||
interrupted = false;
|
interrupted = false;
|
||||||
|
|
||||||
synchronized (Thread.currentThread()) {
|
synchronized (Thread.currentThread()) {
|
||||||
|
synchronized (GameScene.class){
|
||||||
|
GameScene.class.notify();
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
Thread.currentThread().wait();
|
Thread.currentThread().wait();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
|
|
@ -414,17 +414,34 @@ public class GameScene extends PixelScene {
|
||||||
|
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
|
|
||||||
freezeEmitters = false;
|
//tell the actor thread to finish, then wait for it to complete any actions it may be doing.
|
||||||
|
|
||||||
scene = null;
|
|
||||||
Badges.saveGlobal();
|
|
||||||
|
|
||||||
if (actorThread.isAlive()){
|
if (actorThread.isAlive()){
|
||||||
synchronized (actorThread) {
|
synchronized (actorThread) {
|
||||||
actorThread.interrupt();
|
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();
|
super.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user