From ee054d1bf9b89eb29cf28f3f08b71e77a5a4fe04 Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Fri, 7 Jun 2013 02:53:41 +0200 Subject: [PATCH] initialize TileLayer/Manager when added at runtime fixes NPE where TileManager.onUpdate is run without previous init() when TileLayer is added at runtime --- src/org/oscim/layers/tile/TileLayer.java | 7 +++++-- src/org/oscim/layers/tile/TileManager.java | 13 ++++--------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/org/oscim/layers/tile/TileLayer.java b/src/org/oscim/layers/tile/TileLayer.java index c84e3017..e2a912c6 100644 --- a/src/org/oscim/layers/tile/TileLayer.java +++ b/src/org/oscim/layers/tile/TileLayer.java @@ -30,6 +30,8 @@ public abstract class TileLayer extends Layer { protected final int mNumTileLoader = 4; protected final ArrayList mTileLoader; + protected boolean mInitial = true; + public TileLayer(MapView mapView) { this(mapView, MAX_ZOOMLEVEL); } @@ -63,9 +65,10 @@ public abstract class TileLayer extends Layer { @Override public void onUpdate(MapPosition mapPosition, boolean changed, boolean clear) { - if (clear) { + if (clear || mInitial) { mRenderLayer.clearTiles(); - mTileManager.init(mMapView.getWidth(), mMapView.getHeight()); + mTileManager.init(mInitial); + mInitial = false; changed = true; } if (changed) diff --git a/src/org/oscim/layers/tile/TileManager.java b/src/org/oscim/layers/tile/TileManager.java index 8eacf30e..aaa0da7b 100644 --- a/src/org/oscim/layers/tile/TileManager.java +++ b/src/org/oscim/layers/tile/TileManager.java @@ -57,7 +57,6 @@ public class TileManager { private final MapView mMapView; private final MapViewPosition mMapViewPosition; - private boolean mInitialized; // cache for all tiles private MapTile[] mTiles; @@ -132,11 +131,9 @@ public class TileManager { mTilesForUpload = 0; mUpdateSerial = 0; - mInitialized = false; } public void destroy() { - mInitialized = false; // there might be some leaks in here // ... free static pools } @@ -148,13 +145,13 @@ public class TileManager { } - public void init(int width, int height) { + public void init(boolean first) { // sync with GLRender thread // ... and labeling thread? GLRenderer.drawlock.lock(); - if (mInitialized) { + if (!first) { // pass VBOs and VertexItems back to pools for (int i = 0; i < mTilesSize; i++) clearTile(mTiles[i]); @@ -173,7 +170,7 @@ public class TileManager { mTilesCount = 0; // set up TileSet large enough to hold current tiles - int num = Math.max(width, height); + int num = Math.max(mMapView.getWidth(), mMapView.getHeight()); int size = Tile.SIZE >> 1; int numTiles = (num * num) / (size * size) * 4; @@ -181,8 +178,6 @@ public class TileManager { mCurrentTiles = new TileSet(numTiles); Log.d(TAG, "max tiles: " + numTiles); - mInitialized = true; - GLRenderer.drawlock.unlock(); } @@ -612,7 +607,7 @@ public class TileManager { MapTile tile = null; if (cnt == maxTiles) { - Log.d(TAG, "reached maximum tiles " + maxTiles); + Log.wtf(TAG, "reached maximum tiles " + maxTiles); break; } int xx = x;