fix viewable thread-safety

This commit is contained in:
Pyrbu 2025-04-02 23:35:14 +02:00
parent ffe3d3dc35
commit affa0f4c84

View file

@ -11,13 +11,15 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public abstract class Viewable { public abstract class Viewable {
private final static List<WeakReference<Viewable>> all = new ArrayList<>(); private final static List<WeakReference<Viewable>> all = Collections.synchronizedList(new ArrayList<>());
public static List<Viewable> all() { public static List<Viewable> all() {
all.removeIf(reference -> reference.get() == null); synchronized (all) {
return all.stream() all.removeIf(reference -> reference.get() == null);
.map(Reference::get) return all.stream()
.collect(Collectors.toList()); .map(Reference::get)
.collect(Collectors.toList());
}
} }
private boolean queueRunning = false; private boolean queueRunning = false;