From 25c0449bb0fa55bf7e5113efc3eadfdbca32e7d6 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Wed, 23 Aug 2017 03:56:42 -0400 Subject: [PATCH] v0.6.1b: fixed rare concurrent modification of actor sets --- .../shatteredpixeldungeon/actors/Actor.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 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 6d3640413..36685148b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java @@ -100,13 +100,12 @@ public abstract class Actor implements Bundlable { private static HashSet all = new HashSet<>(); private static HashSet chars = new HashSet<>(); private static volatile Actor current; - private static volatile boolean processing; private static SparseArray ids = new SparseArray<>(); private static float now = 0; - public static void clear() { + public static synchronized void clear() { now = 0; @@ -116,7 +115,7 @@ public abstract class Actor implements Bundlable { ids.clear(); } - public static void fixTime() { + public static synchronized void fixTime() { if (Dungeon.hero != null && all.contains( Dungeon.hero )) { Statistics.duration += now; @@ -264,7 +263,7 @@ public abstract class Actor implements Bundlable { add( actor, now + delay ); } - private static void add( Actor actor, float time ) { + private static synchronized void add( Actor actor, float time ) { if (all.contains( actor )) { return; @@ -286,7 +285,7 @@ public abstract class Actor implements Bundlable { } } - public static void remove( Actor actor ) { + public static synchronized void remove( Actor actor ) { if (actor != null) { all.remove( actor ); @@ -299,7 +298,7 @@ public abstract class Actor implements Bundlable { } } - public static Char findChar( int pos ) { + public static synchronized Char findChar( int pos ) { for (Char ch : chars){ if (ch.pos == pos) return ch; @@ -307,13 +306,13 @@ public abstract class Actor implements Bundlable { return null; } - public static Actor findById( int id ) { + public static synchronized Actor findById( int id ) { return ids.get( id ); } - public static HashSet all() { - return all; + public static synchronized HashSet all() { + return new HashSet(all); } - public static HashSet chars() { return chars; } + public static synchronized HashSet chars() { return new HashSet(chars); } }