add a little extra safety to ensure the updater thread stops on dispose
This commit is contained in:
parent
75691fa357
commit
da47617e9f
|
@ -15,6 +15,7 @@ public class TileMap extends TileContainer implements Disposable {
|
|||
final Vector3 tmpPosition = new Vector3();
|
||||
|
||||
TileMapUpdater updater;
|
||||
Thread updaterThread;
|
||||
|
||||
public final int chunkWidth;
|
||||
public final int chunkHeight;
|
||||
|
@ -149,6 +150,7 @@ public class TileMap extends TileContainer implements Disposable {
|
|||
bounds.max.set(getWidth(), getHeight(), getDepth());
|
||||
|
||||
updater = new TileMapUpdater(this);
|
||||
updaterThread = null;
|
||||
}
|
||||
|
||||
public void updateVertices() {
|
||||
|
@ -160,7 +162,8 @@ public class TileMap extends TileContainer implements Disposable {
|
|||
if (isUpdating())
|
||||
throw new IllegalStateException("Async vertices update for this TileMap is currently underway.");
|
||||
|
||||
(new Thread(updater)).start();
|
||||
updaterThread = new Thread(updater);
|
||||
updaterThread.start();
|
||||
}
|
||||
|
||||
public boolean updateVerticesAsync() {
|
||||
|
@ -294,6 +297,7 @@ public class TileMap extends TileContainer implements Disposable {
|
|||
|
||||
@Override
|
||||
public void dispose() {
|
||||
updater.signalStop();
|
||||
for (int i = 0; i < chunks.length; ++i)
|
||||
chunks[i].dispose();
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ public class TileMapUpdater implements Runnable {
|
|||
TileChunk chunkNeedingVboCreation;
|
||||
float progress;
|
||||
boolean isRunning;
|
||||
boolean needToStop;
|
||||
|
||||
public TileMapUpdater(TileMap tileMap) {
|
||||
this.tileMap = tileMap;
|
||||
|
@ -32,14 +33,17 @@ public class TileMapUpdater implements Runnable {
|
|||
waitingForVboCreation = false;
|
||||
}
|
||||
|
||||
public synchronized void signalStop() { needToStop = true; }
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
isRunning = true;
|
||||
chunkNeedingVboCreation = null;
|
||||
needToStop = false;
|
||||
|
||||
TileChunk[] chunks = tileMap.getChunks();
|
||||
|
||||
for (int i = 0; i < tileMap.chunks.length; ++i) {
|
||||
for (int i = 0; (i < tileMap.chunks.length && !needToStop); ++i) {
|
||||
progress = (float)i / (float)(chunks.length - 1);
|
||||
|
||||
TileChunk chunk = chunks[i];
|
||||
|
|
Loading…
Reference in a new issue