Authored by Thomas Rasch

Merge branch 'release' into develop

@@ -124,6 +124,9 @@ @@ -124,6 +124,9 @@
124 { 124 {
125 RMLog(@"Opening db map source %@", path); 125 RMLog(@"Opening db map source %@", path);
126 126
  127 + // Debug mode
  128 +// [db setTraceExecution:YES];
  129 +
127 // get the tile side length 130 // get the tile side length
128 tileSideLength = [self getPreferenceAsInt:kTileSideLengthKey]; 131 tileSideLength = [self getPreferenceAsInt:kTileSideLengthKey];
129 132
@@ -189,22 +192,25 @@ @@ -189,22 +192,25 @@
189 192
190 - (UIImage *)imageForTileImage:(RMTileImage *)tileImage addToCache:(RMTileCache *)tileCache withCacheKey:(NSString *)aCacheKey 193 - (UIImage *)imageForTileImage:(RMTileImage *)tileImage addToCache:(RMTileCache *)tileCache withCacheKey:(NSString *)aCacheKey
191 { 194 {
  195 + UIImage *image = nil;
  196 +
192 RMTile tile = [[self mercatorToTileProjection] normaliseTile:tileImage.tile]; 197 RMTile tile = [[self mercatorToTileProjection] normaliseTile:tileImage.tile];
193 198
194 // get the unique key for the tile 199 // get the unique key for the tile
195 NSNumber *key = [NSNumber numberWithLongLong:RMTileKey(tile)]; 200 NSNumber *key = [NSNumber numberWithLongLong:RMTileKey(tile)];
196 201
  202 + @synchronized(db) {
197 // fetch the image from the db 203 // fetch the image from the db
198 FMResultSet *result = [db executeQuery:@"SELECT image FROM tiles WHERE tilekey = ?", key]; 204 FMResultSet *result = [db executeQuery:@"SELECT image FROM tiles WHERE tilekey = ?", key];
199 FMDBErrorCheck(db); 205 FMDBErrorCheck(db);
200 206
201 - UIImage *image = nil;  
202 if ([result next]) { 207 if ([result next]) {
203 - image = [[[UIImage alloc] initWithData:[result dataForColumn:@"image"]] autorelease]; 208 + image = [[[UIImage alloc] initWithData:[result dataForColumnIndex:0]] autorelease];
204 } else { 209 } else {
205 image = [RMTileImage missingTile]; 210 image = [RMTileImage missingTile];
206 } 211 }
207 [result close]; 212 [result close];
  213 + }
208 214
209 if (tileCache) 215 if (tileCache)
210 [tileCache addImage:image forTile:tile withCacheKey:aCacheKey]; 216 [tileCache addImage:image forTile:tile withCacheKey:aCacheKey];
@@ -258,11 +264,13 @@ @@ -258,11 +264,13 @@
258 { 264 {
259 NSString* value = nil; 265 NSString* value = nil;
260 266
  267 + @synchronized(db) {
261 FMResultSet *result = [db executeQuery:@"select value from preferences where name = ?", name]; 268 FMResultSet *result = [db executeQuery:@"select value from preferences where name = ?", name];
262 if ([result next]) { 269 if ([result next]) {
263 value = [result stringForColumn:@"value"]; 270 value = [result stringForColumn:@"value"];
264 } 271 }
265 [result close]; 272 [result close];
  273 + }
266 274
267 return value; 275 return value;
268 } 276 }