Fix possible CursorWindowAllocationException
This commit is contained in:
parent
f7790ef2c7
commit
7d529dc42a
2 changed files with 26 additions and 25 deletions
|
@ -509,26 +509,27 @@ public class SQLiteTileSource implements ITileSource {
|
||||||
if(db == null || coordinatesZoom > 25 ){
|
if(db == null || coordinatesZoom > 25 ){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
SQLiteCursor q ;
|
SQLiteCursor cursor ;
|
||||||
if (inversiveZoom) {
|
if (inversiveZoom) {
|
||||||
int minZoom = (17 - minZ) + 1;
|
int minZoom = (17 - minZ) + 1;
|
||||||
// 17 - z = zoom, x << (25 - zoom) = 25th x tile = 8 + z,
|
// 17 - z = zoom, x << (25 - zoom) = 25th x tile = 8 + z,
|
||||||
q = db.rawQuery("SELECT max(x << (8+z)), min(x << (8+z)), max(y << (8+z)), min(y << (8+z))" +
|
cursor = db.rawQuery("SELECT max(x << (8+z)), min(x << (8+z)), max(y << (8+z)), min(y << (8+z))" +
|
||||||
" from tiles where z < "
|
" from tiles where z < "
|
||||||
+ minZoom, new String[0]);
|
+ minZoom, new String[0]);
|
||||||
} else {
|
} else {
|
||||||
q = db.rawQuery("SELECT max(x << (25-z)), min(x << (25-z)), max(y << (25-z)), min(y << (25-z))"
|
cursor = db.rawQuery("SELECT max(x << (25-z)), min(x << (25-z)), max(y << (25-z)), min(y << (25-z))"
|
||||||
+ " from tiles where z > " + minZ,
|
+ " from tiles where z > " + minZ,
|
||||||
new String[0]);
|
new String[0]);
|
||||||
}
|
}
|
||||||
q.moveToFirst();
|
cursor.moveToFirst();
|
||||||
int right = (int) (q.getInt(0) >> (25 - coordinatesZoom));
|
int right = (int) (cursor.getInt(0) >> (25 - coordinatesZoom));
|
||||||
int left = (int) (q.getInt(1) >> (25 - coordinatesZoom));
|
int left = (int) (cursor.getInt(1) >> (25 - coordinatesZoom));
|
||||||
int top = (int) (q.getInt(3) >> (25 - coordinatesZoom));
|
int top = (int) (cursor.getInt(3) >> (25 - coordinatesZoom));
|
||||||
int bottom = (int) (q.getInt(2) >> (25 - coordinatesZoom));
|
int bottom = (int) (cursor.getInt(2) >> (25 - coordinatesZoom));
|
||||||
|
|
||||||
|
cursor.close();
|
||||||
|
|
||||||
return new QuadRect(left, top, right, bottom);
|
return new QuadRect(left, top, right, bottom);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteImage(int x, int y, int zoom) {
|
public void deleteImage(int x, int y, int zoom) {
|
||||||
|
|
|
@ -36,7 +36,7 @@ import static net.osmand.plus.settings.backend.OsmandSettings.TerrainMode.HILLSH
|
||||||
public class TerrainLayer extends MapTileLayer {
|
public class TerrainLayer extends MapTileLayer {
|
||||||
|
|
||||||
private final static Log log = PlatformUtil.getLog(TerrainLayer.class);
|
private final static Log log = PlatformUtil.getLog(TerrainLayer.class);
|
||||||
private Map<String, SQLiteTileSource> resources = new LinkedHashMap<String, SQLiteTileSource>();
|
private Map<String, SQLiteTileSource> resources = new LinkedHashMap<String, SQLiteTileSource>();
|
||||||
private final static String HILLSHADE_CACHE = "hillshade.cache";
|
private final static String HILLSHADE_CACHE = "hillshade.cache";
|
||||||
private final static String SLOPE_CACHE = "slope.cache";
|
private final static String SLOPE_CACHE = "slope.cache";
|
||||||
private int ZOOM_BOUNDARY = 15;
|
private int ZOOM_BOUNDARY = 15;
|
||||||
|
@ -69,7 +69,6 @@ public class TerrainLayer extends MapTileLayer {
|
||||||
} else {
|
} else {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void indexTerrainFiles(final OsmandApplication app) {
|
private void indexTerrainFiles(final OsmandApplication app) {
|
||||||
|
@ -78,7 +77,6 @@ public class TerrainLayer extends MapTileLayer {
|
||||||
private String type = mode.name().toLowerCase();
|
private String type = mode.name().toLowerCase();
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... params) {
|
protected Void doInBackground(Void... params) {
|
||||||
|
|
||||||
File tilesDir = app.getAppPath(IndexConstants.TILES_INDEX_DIR);
|
File tilesDir = app.getAppPath(IndexConstants.TILES_INDEX_DIR);
|
||||||
File cacheDir = app.getCacheDir();
|
File cacheDir = app.getCacheDir();
|
||||||
// fix http://stackoverflow.com/questions/26937152/workaround-for-nexus-9-sqlite-file-write-operations-on-external-dirs
|
// fix http://stackoverflow.com/questions/26937152/workaround-for-nexus-9-sqlite-file-write-operations-on-external-dirs
|
||||||
|
@ -92,17 +90,21 @@ public class TerrainLayer extends MapTileLayer {
|
||||||
sqliteDb = null;
|
sqliteDb = null;
|
||||||
}
|
}
|
||||||
if (sqliteDb != null) {
|
if (sqliteDb != null) {
|
||||||
if (sqliteDb.getVersion() == 0) {
|
try {
|
||||||
sqliteDb.setVersion(1);
|
if (sqliteDb.getVersion() == 0) {
|
||||||
}
|
sqliteDb.setVersion(1);
|
||||||
sqliteDb.execSQL("CREATE TABLE IF NOT EXISTS TILE_SOURCES(filename varchar2(256), date_modified int, left int, right int, top int, bottom int)");
|
}
|
||||||
|
sqliteDb.execSQL("CREATE TABLE IF NOT EXISTS TILE_SOURCES(filename varchar2(256), date_modified int, left int, right int, top int, bottom int)");
|
||||||
|
|
||||||
Map<String, Long> fileModified = new HashMap<String, Long>();
|
Map<String, Long> fileModified = new HashMap<String, Long>();
|
||||||
Map<String, SQLiteTileSource> rs = readFiles(app, tilesDir, fileModified);
|
Map<String, SQLiteTileSource> rs = readFiles(app, tilesDir, fileModified);
|
||||||
indexCachedResources(fileModified, rs);
|
indexCachedResources(fileModified, rs);
|
||||||
indexNonCachedResources(fileModified, rs);
|
indexNonCachedResources(fileModified, rs);
|
||||||
sqliteDb.close();
|
sqliteDb.close();
|
||||||
resources = rs;
|
resources = rs;
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -151,7 +153,6 @@ public class TerrainLayer extends MapTileLayer {
|
||||||
indexedResources.insert(filename, new QuadRect(left, top, right, bottom));
|
indexedResources.insert(filename, new QuadRect(left, top, right, bottom));
|
||||||
fileModified.remove(filename);
|
fileModified.remove(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
} while(cursor.moveToNext());
|
} while(cursor.moveToNext());
|
||||||
}
|
}
|
||||||
cursor.close();
|
cursor.close();
|
||||||
|
@ -173,7 +174,6 @@ public class TerrainLayer extends MapTileLayer {
|
||||||
}
|
}
|
||||||
return rs;
|
return rs;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
executeTaskInBackground(task);
|
executeTaskInBackground(task);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue