TileManager: just drop index on re-init

- dont modify index of locked tiles..
- fixes one more bug from monkey test
This commit is contained in:
Hannes Janetzek 2014-10-06 17:36:09 +02:00
parent d1daa92126
commit ded178be6c
3 changed files with 33 additions and 34 deletions

View File

@ -22,7 +22,6 @@ 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.NONE;
import static org.oscim.layers.tile.MapTile.State.READY; import static org.oscim.layers.tile.MapTile.State.READY;
import static org.oscim.layers.tile.MapTile.State.TIMEOUT;
import org.oscim.core.Tile; import org.oscim.core.Tile;
import org.oscim.layers.tile.vector.VectorTileLoader; import org.oscim.layers.tile.vector.VectorTileLoader;
@ -74,8 +73,6 @@ public class MapTile extends Tile {
*/ */
public final static byte CANCEL = (1 << 4); public final static byte CANCEL = (1 << 4);
public final static byte TIMEOUT = (1 << 5);
/** /**
* Dont touch if you find some. * Dont touch if you find some.
*/ */
@ -231,12 +228,6 @@ public class MapTile extends Tile {
if (--locked > 0) if (--locked > 0)
return; return;
if (state == DEADBEEF) {
log.debug("Unlock dead tile {}", this);
clear();
return;
}
TileNode parent = node.parent; TileNode parent = node.parent;
if ((proxy & PROXY_PARENT) != 0) if ((proxy & PROXY_PARENT) != 0)
parent.item.refs--; parent.item.refs--;
@ -252,6 +243,11 @@ public class MapTile extends Tile {
/* removed all proxy references for this tile */ /* removed all proxy references for this tile */
proxy = 0; proxy = 0;
if (state == DEADBEEF) {
log.debug("Unlock dead tile {}", this);
clear();
}
} }
/** /**
@ -278,10 +274,7 @@ public class MapTile extends Tile {
data.dispose(); data.dispose();
data = data.next; data = data.next;
} }
if (state == DEADBEEF) setState(NONE);
return;
state = NONE;
} }
/** /**
@ -402,26 +395,27 @@ public class MapTile extends Tile {
return "Ready"; return "Ready";
case State.CANCEL: case State.CANCEL:
return "Cancel"; return "Cancel";
case State.TIMEOUT:
return "Timeout";
case State.DEADBEEF: case State.DEADBEEF:
return "Dead"; return "Dead";
} }
return ""; return "";
} }
void setState(byte newState) { public synchronized void setState(byte newState) {
if (state == newState) if (state == newState)
return; return;
/* Renderer could have uploaded the tile while the layer
* was cleared. This prevents to set tile to READY state. */
/* All other state changes are on the main-thread. */
if (state == DEADBEEF)
return;
switch (newState) { switch (newState) {
case NONE: case NONE:
if (state(LOADING | CANCEL)) {
state = newState; state = newState;
return; return;
}
throw new IllegalStateException("None"
+ " <= " + state() + " " + this);
case LOADING: case LOADING:
if (state == NONE) { if (state == NONE) {
state = newState; state = newState;
@ -452,12 +446,9 @@ public class MapTile extends Tile {
} }
throw new IllegalStateException("Cancel" + throw new IllegalStateException("Cancel" +
" <= " + state() + " " + this); " <= " + state() + " " + this);
case TIMEOUT:
// TODO
break;
case DEADBEEF: case DEADBEEF:
state = newState; state = newState;
break; return;
} }
} }
} }

View File

@ -167,20 +167,22 @@ public class TileManager {
public void init() { public void init() {
if (mCurrentTiles != null) if (mCurrentTiles != null)
mCurrentTiles.releaseTiles(); mCurrentTiles.releaseTiles();
/* pass VBOs and VertexItems back to pools */
mIndex.drop();
/* Pass VBOs and VertexItems back to pools */
for (int i = 0; i < mTilesEnd; i++) { for (int i = 0; i < mTilesEnd; i++) {
MapTile t = mTiles[i]; MapTile t = mTiles[i];
if (t == null) if (t == null)
continue; continue;
if (!t.isLocked()) { /* Check if tile is used by another thread */
//log.debug("init clear {} {}", t, t.state()); if (!t.isLocked())
t.clear(); t.clear();
}
mIndex.removeItem(t);
/* in case the tile is still loading: /* In case the tile is still loading or used by
* clear when returned from loader */ * another thread: clear when returned from loader
* or becomes unlocked */
t.setState(DEADBEEF); t.setState(DEADBEEF);
} }
@ -592,7 +594,6 @@ public class TileManager {
mTilesToUpload++; mTilesToUpload++;
return; return;
} }
// TODO use mMap.update(true) to retry tile loading? // TODO use mMap.update(true) to retry tile loading?
log.debug("Load: {} {} state:{}", log.debug("Load: {} {} state:{}",
tile, success ? "success" : "failed", tile, success ? "success" : "failed",

View File

@ -195,4 +195,11 @@ public abstract class TileIndex<T extends TreeNode<T, E>, E> {
return root.refs; return root.refs;
} }
public void drop() {
root.item = null;
root.child00 = null;
root.child01 = null;
root.child10 = null;
root.child11 = null;
}
} }