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 -  
197 - // fetch the image from the db  
198 - FMResultSet *result = [db executeQuery:@"SELECT image FROM tiles WHERE tilekey = ?", key];  
199 - FMDBErrorCheck(db);  
200 201
201 - UIImage *image = nil;  
202 - if ([result next]) {  
203 - image = [[[UIImage alloc] initWithData:[result dataForColumn:@"image"]] autorelease];  
204 - } else {  
205 - image = [RMTileImage missingTile]; 202 + @synchronized(db) {
  203 + // fetch the image from the db
  204 + FMResultSet *result = [db executeQuery:@"SELECT image FROM tiles WHERE tilekey = ?", key];
  205 + FMDBErrorCheck(db);
  206 +
  207 + if ([result next]) {
  208 + image = [[[UIImage alloc] initWithData:[result dataForColumnIndex:0]] autorelease];
  209 + } else {
  210 + image = [RMTileImage missingTile];
  211 + }
  212 + [result close];
206 } 213 }
207 - [result close];  
208 214
209 if (tileCache) 215 if (tileCache)
210 [tileCache addImage:image forTile:tile withCacheKey:aCacheKey]; 216 [tileCache addImage:image forTile:tile withCacheKey:aCacheKey];
@@ -257,12 +263,14 @@ @@ -257,12 +263,14 @@
257 - (NSString *)getPreferenceAsString:(NSString*)name 263 - (NSString *)getPreferenceAsString:(NSString*)name
258 { 264 {
259 NSString* value = nil; 265 NSString* value = nil;
260 -  
261 - FMResultSet *result = [db executeQuery:@"select value from preferences where name = ?", name];  
262 - if ([result next]) {  
263 - value = [result stringForColumn:@"value"];  
264 - }  
265 - [result close]; 266 +
  267 + @synchronized(db) {
  268 + FMResultSet *result = [db executeQuery:@"select value from preferences where name = ?", name];
  269 + if ([result next]) {
  270 + value = [result stringForColumn:@"value"];
  271 + }
  272 + [result close];
  273 + }
266 274
267 return value; 275 return value;
268 } 276 }