@@ -454,45 +454,42 @@ bool OpenStreetMap::fetchTile(CachedTile &tile, uint32_t x, uint32_t y, uint8_t
454
454
return false ;
455
455
}
456
456
457
+ PNG *png = getPNGForCore ();
458
+ if (!png)
459
+ {
460
+ result = " PNG decoder unavailable" ;
461
+ return false ;
462
+ }
463
+
457
464
char url[64 ];
458
465
snprintf (url, sizeof (url), " https://tile.openstreetmap.org/%u/%u/%u.png" ,
459
466
static_cast <unsigned int >(zoom),
460
467
static_cast <unsigned int >(x),
461
468
static_cast <unsigned int >(y));
462
469
463
- int decodeResult;
464
- {
465
- auto buffer = urlToBuffer (url, result);
466
- if (!buffer)
467
- return false ;
468
-
469
- PNG *png = getPNGForCore ();
470
- if (!png)
471
- {
472
- result = " PNG decoder unavailable" ;
473
- return false ;
474
- }
475
-
476
- const int16_t rc = png->openRAM (buffer.value ()->get (), buffer.value ()->size (), PNGDraw);
477
- if (rc != PNG_SUCCESS)
478
- {
479
- result = " PNG Decoder Error: " + String (rc);
480
- return false ;
481
- }
470
+ const auto buffer = urlToBuffer (url, result);
471
+ if (!buffer)
472
+ return false ;
482
473
483
- if (png->getWidth () != OSM_TILESIZE || png->getHeight () != OSM_TILESIZE)
484
- {
485
- result = " Unexpected tile size: w=" + String (png->getWidth ()) + " h=" + String (png->getHeight ());
486
- return false ;
487
- }
474
+ const int16_t rc = png->openRAM (buffer.value ()->get (), buffer.value ()->size (), PNGDraw);
475
+ if (rc != PNG_SUCCESS)
476
+ {
477
+ result = " PNG Decoder Error: " + String (rc);
478
+ return false ;
479
+ }
488
480
489
- currentInstance = this ;
490
- currentTileBuffer = tile.buffer ;
491
- decodeResult = png->decode (0 , PNG_FAST_PALETTE);
492
- currentTileBuffer = nullptr ;
493
- currentInstance = nullptr ;
481
+ if (png->getWidth () != OSM_TILESIZE || png->getHeight () != OSM_TILESIZE)
482
+ {
483
+ result = " Unexpected tile size: w=" + String (png->getWidth ()) + " h=" + String (png->getHeight ());
484
+ return false ;
494
485
}
495
486
487
+ currentInstance = this ;
488
+ currentTileBuffer = tile.buffer ;
489
+ const int decodeResult = png->decode (0 , PNG_FAST_PALETTE);
490
+ currentTileBuffer = nullptr ;
491
+ currentInstance = nullptr ;
492
+
496
493
if (decodeResult != PNG_SUCCESS)
497
494
{
498
495
result = " Decoding " + String (url) + " failed with code: " + String (decodeResult);
0 commit comments