From fe23143d0ea1b48cf7b9dde8b7b7ab03c63ccd75 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Fri, 4 Sep 2020 23:31:53 -0400 Subject: [PATCH] v0.9.0: fixed a race condition when 'now' is read as it is being updated --- .../shatteredpixeldungeon/actors/Actor.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java index 78da507ef..e74c42bb5 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java @@ -215,14 +215,14 @@ public abstract class Actor implements Bundlable { current = null; if (!interrupted) { - now = Float.MAX_VALUE; - + float earliest = Float.MAX_VALUE; + for (Actor actor : all) { //some actors will always go before others if time is equal. - if (actor.time < now || - actor.time == now && (current == null || actor.actPriority > current.actPriority)) { - now = actor.time; + if (actor.time < earliest || + actor.time == earliest && (current == null || actor.actPriority > current.actPriority)) { + earliest = actor.time; current = actor; } @@ -231,6 +231,7 @@ public abstract class Actor implements Bundlable { if (current != null) { + now = current.time; Actor acting = current; if (acting instanceof Char && ((Char) acting).sprite != null) {