fix: TileManager reload failed tiles
- properly clear previous TileSet - CANCEL state tiles will be cleared when they return from tile-worker
This commit is contained in:
parent
e20a342f81
commit
5109eda6da
@ -18,9 +18,9 @@
|
|||||||
package org.oscim.layers.tile;
|
package org.oscim.layers.tile;
|
||||||
|
|
||||||
import static org.oscim.layers.tile.MapTile.State.CANCEL;
|
import static org.oscim.layers.tile.MapTile.State.CANCEL;
|
||||||
|
import static org.oscim.layers.tile.MapTile.State.DEADBEEF;
|
||||||
import static org.oscim.layers.tile.MapTile.State.LOADING;
|
import static org.oscim.layers.tile.MapTile.State.LOADING;
|
||||||
import static org.oscim.layers.tile.MapTile.State.NEW_DATA;
|
import static org.oscim.layers.tile.MapTile.State.NEW_DATA;
|
||||||
import static org.oscim.layers.tile.MapTile.State.NONE;
|
|
||||||
import static org.oscim.layers.tile.MapTile.State.READY;
|
import static org.oscim.layers.tile.MapTile.State.READY;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -169,8 +169,8 @@ public class TileManager {
|
|||||||
for (int i = 0; i < mTilesSize; i++) {
|
for (int i = 0; i < mTilesSize; i++) {
|
||||||
if (mTiles[i] == null)
|
if (mTiles[i] == null)
|
||||||
continue;
|
continue;
|
||||||
mTiles[i].state = NONE;
|
|
||||||
removeFromCache(mTiles[i]);
|
removeFromCache(mTiles[i]);
|
||||||
|
mTiles[i].state = CANCEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* clear references to cached MapTiles */
|
/* clear references to cached MapTiles */
|
||||||
@ -387,12 +387,12 @@ public class TileManager {
|
|||||||
|
|
||||||
if (mLoadParent && (zoomLevel > mMinZoom) && (mZoomTable == null)) {
|
if (mLoadParent && (zoomLevel > mMinZoom) && (mZoomTable == null)) {
|
||||||
/* prefetch parent */
|
/* prefetch parent */
|
||||||
MapTile p = tile.node.parent.item;
|
MapTile p = tile.node.parent();
|
||||||
if (p == null) {
|
if (p == null) {
|
||||||
TileNode n = mIndex.add(x >> 1, y >> 1, zoomLevel - 1);
|
TileNode n = mIndex.add(x >> 1, y >> 1, zoomLevel - 1);
|
||||||
p = n.item = new MapTile(n, x >> 1, y >> 1, zoomLevel - 1);
|
p = n.item = new MapTile(n, x >> 1, y >> 1, zoomLevel - 1);
|
||||||
addToCache(p);
|
addToCache(p);
|
||||||
/* hack to not add tile twice to queue */
|
/* this prevents to add tile twice to queue */
|
||||||
p.state = LOADING;
|
p.state = LOADING;
|
||||||
mJobs.add(p);
|
mJobs.add(p);
|
||||||
} else if (!p.isActive()) {
|
} else if (!p.isActive()) {
|
||||||
@ -432,10 +432,9 @@ public class TileManager {
|
|||||||
if (dbg)
|
if (dbg)
|
||||||
log.debug("remove from cache {} {} {}", t, t.state, t.isLocked());
|
log.debug("remove from cache {} {} {}", t, t.state, t.isLocked());
|
||||||
|
|
||||||
//synchronized (t) {
|
|
||||||
/* When in CANCEL state tile belongs to TileLoader thread,
|
/* When in CANCEL state tile belongs to TileLoader thread,
|
||||||
* defer clearing to jobCompleted() */
|
* defer clearing to jobCompleted() */
|
||||||
if (t.state(NEW_DATA | READY))
|
if (t.state != CANCEL)
|
||||||
t.clear();
|
t.clear();
|
||||||
|
|
||||||
mIndex.removeItem(t);
|
mIndex.removeItem(t);
|
||||||
@ -460,16 +459,24 @@ public class TileManager {
|
|||||||
if (t.state == NEW_DATA)
|
if (t.state == NEW_DATA)
|
||||||
newTileCnt++;
|
newTileCnt++;
|
||||||
|
|
||||||
|
if (t.state == DEADBEEF) {
|
||||||
|
//log.debug("found DEADBEEF {}", t);
|
||||||
|
tiles[i] = null;
|
||||||
|
mTilesCount--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
/* make sure tile cannot be used by GL or MapWorker Thread */
|
/* make sure tile cannot be used by GL or MapWorker Thread */
|
||||||
if ((t.state != 0) || t.isLocked()) {
|
if ((t.state != 0) || t.isLocked()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* empty tile */
|
||||||
removeFromCache(t);
|
removeFromCache(t);
|
||||||
tiles[i] = null;
|
tiles[i] = null;
|
||||||
remove--;
|
remove--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remove < CACHE_CLEAR_THRESHOLD && newTileCnt < MAX_TILES_IN_QUEUE)
|
if ((remove < CACHE_CLEAR_THRESHOLD) && (newTileCnt < MAX_TILES_IN_QUEUE))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
updateDistances(tiles, size, pos);
|
updateDistances(tiles, size, pos);
|
||||||
@ -482,31 +489,30 @@ public class TileManager {
|
|||||||
// log.debug("remove:" + remove + " new:" + newTileCnt);
|
// log.debug("remove:" + remove + " new:" + newTileCnt);
|
||||||
// log.debug("cur: " + mapPosition);
|
// log.debug("cur: " + mapPosition);
|
||||||
|
|
||||||
|
/* start with farest away tile */
|
||||||
for (int i = size - 1; i >= 0 && remove > 0; i--) {
|
for (int i = size - 1; i >= 0 && remove > 0; i--) {
|
||||||
MapTile t = tiles[i];
|
MapTile t = tiles[i];
|
||||||
if (t.isLocked()) {
|
|
||||||
/* dont remove tile used by TileRenderer, or somewhere else
|
/* dont remove tile used by TileRenderer, or somewhere else
|
||||||
* try again in next run. */
|
* try again in next run. */
|
||||||
|
if (t.isLocked()) {
|
||||||
if (dbg)
|
if (dbg)
|
||||||
log.debug("{} locked (state={}, d={})", t, t.state, t.distance);
|
log.debug("{} locked (state={}, d={})", t, t.state, t.distance);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* cancel loading of tiles that should not even be cached */
|
||||||
if (t.state == LOADING) {
|
if (t.state == LOADING) {
|
||||||
/* NOTE: when set loading to false the tile could be
|
|
||||||
* added to load queue again while still processed in
|
|
||||||
* VectorTileLoader */
|
|
||||||
t.state = CANCEL;
|
t.state = CANCEL;
|
||||||
if (dbg)
|
if (dbg)
|
||||||
log.debug("{} canceled (d={})", t, t.distance);
|
log.debug("{} canceled (d={})", t, t.distance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* clear new and unused tile */
|
||||||
if (t.state == NEW_DATA) {
|
if (t.state == NEW_DATA) {
|
||||||
/* clear unused tile */
|
newTileCnt--;
|
||||||
if (dbg)
|
if (dbg)
|
||||||
log.debug("{} unused (d=({})", t, t.distance);
|
log.debug("{} unused (d=({})", t, t.distance);
|
||||||
newTileCnt--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
removeFromCache(t);
|
removeFromCache(t);
|
||||||
@ -515,21 +521,17 @@ public class TileManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
remove = (newTileCnt - MAX_TILES_IN_QUEUE) + QUEUE_CLEAR_THRESHOLD;
|
remove = (newTileCnt - MAX_TILES_IN_QUEUE) + QUEUE_CLEAR_THRESHOLD;
|
||||||
//int r = remove;
|
|
||||||
for (int i = size - 1; i >= 0 && remove > 0; i--) {
|
for (int i = size - 1; i >= 0 && remove > 0; i--) {
|
||||||
MapTile t = tiles[i];
|
MapTile t = tiles[i];
|
||||||
if (t != null && !t.isLocked() && t.state == NEW_DATA) {
|
if ((t != null) && (t.state == NEW_DATA) && !t.isLocked()) {
|
||||||
newTileCnt--;
|
|
||||||
removeFromCache(t);
|
removeFromCache(t);
|
||||||
tiles[i] = null;
|
tiles[i] = null;
|
||||||
remove--;
|
remove--;
|
||||||
|
newTileCnt--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mTilesForUpload += newTileCnt;
|
mTilesForUpload += newTileCnt;
|
||||||
//log.debug("cleanup load queue {} / {} - {}", mTilesForUpload, r, remove);
|
|
||||||
if (dbg)
|
|
||||||
log.debug("cleanup: {} {}", mTilesCount, mTilesForUpload);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -562,7 +564,6 @@ public class TileManager {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (success && tile.state != CANCEL) {
|
if (success && tile.state != CANCEL) {
|
||||||
|
|
||||||
tile.state = NEW_DATA;
|
tile.state = NEW_DATA;
|
||||||
events.fire(TILE_LOADED, tile);
|
events.fire(TILE_LOADED, tile);
|
||||||
|
|
||||||
@ -575,10 +576,10 @@ public class TileManager {
|
|||||||
success ? "canceled"
|
success ? "canceled"
|
||||||
: "failed");
|
: "failed");
|
||||||
|
|
||||||
tile.clear();
|
|
||||||
|
|
||||||
if (tile.state == LOADING)
|
if (tile.state == LOADING)
|
||||||
mIndex.removeItem(tile);
|
mIndex.removeItem(tile);
|
||||||
|
|
||||||
|
tile.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user