Skip to content

Commit

Permalink
Fix for ConcurrentModificationException
Browse files Browse the repository at this point in the history
 * Make partialPaths thread safe and Close #328

Signed-off-by: JamzTheMan <JamzTheMan@gmail.com>
  • Loading branch information
JamzTheMan committed Sep 7, 2019
1 parent 5c940f7 commit d46202c
Showing 1 changed file with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@
*/
package net.rptools.maptool.client.walker;

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import net.rptools.maptool.client.ui.zone.RenderPathWorker;
import net.rptools.maptool.model.CellPoint;
import net.rptools.maptool.model.Path;
import net.rptools.maptool.model.Zone;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;

public abstract class AbstractZoneWalker implements ZoneWalker {
protected List<PartialPath> partialPaths = new ArrayList<PartialPath>();
protected List<PartialPath> partialPaths =
Collections.synchronizedList(new ArrayList<PartialPath>());
protected final Zone zone;
protected boolean restrictMovement = false;
protected RenderPathWorker renderPathWorker;
Expand All @@ -37,11 +40,10 @@ public Zone getZone() {
}

public CellPoint getLastPoint() {
if (partialPaths.isEmpty()) {
return null;
synchronized (partialPaths) {
if (partialPaths.isEmpty()) return null;
else return partialPaths.get(partialPaths.size() - 1).end;
}
PartialPath lastPath = partialPaths.get(partialPaths.size() - 1);
return lastPath.end;
}

public void setWaypoints(CellPoint... points) {
Expand Down Expand Up @@ -96,20 +98,26 @@ public Path<CellPoint> getPath() {
Path<CellPoint> path = new Path<CellPoint>();

PartialPath last = null;
for (PartialPath partial : partialPaths) {
if (partial.path != null && partial.path.size() > 1) {
path.addAllPathCells(partial.path.subList(0, partial.path.size() - 1));

synchronized (partialPaths) {
for (PartialPath partial : partialPaths) {
if (partial.path != null && partial.path.size() > 1) {
path.addAllPathCells(partial.path.subList(0, partial.path.size() - 1));
}
last = partial;
}
last = partial;
}

if (last != null) {
path.addPathCell(last.end);
}

for (CellPoint cp : path.getCellPath()) {
if (isWaypoint(cp)) {
path.addWayPoint(cp);
}
}

return path;
}

Expand Down

0 comments on commit d46202c

Please sign in to comment.