Skip to content

Commit c6bcd03

Browse files
Prevent duplicate tile fetch jobs (#106)
Avoid duplicate tile downloads at low zoom levels by reusing already queued jobs * Prevents wrapping tiles from being redundantly fetched multiple times * `makeJobList()` now checks if a tile is already queued and reuses its buffer * Maintains 1:1 alignment between `requiredTiles` and `tilePointers`
1 parent e929b41 commit c6bcd03

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/OpenStreetMap-esp32.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,24 @@ void OpenStreetMap::makeJobList(const tileList &requiredTiles, std::vector<TileJ
225225
if (isTileCached(x, y, zoom, tilePointers)) // isTileCached will push_back a valid ptr if tile is cached
226226
continue;
227227

228+
// Check if this tile is already in the job list
229+
auto existing = std::find_if(jobs.begin(), jobs.end(), [&](const TileJob &job)
230+
{ return job.x == x && job.y == static_cast<uint32_t>(y) && job.z == zoom; });
231+
if (existing != jobs.end())
232+
{
233+
tilePointers.push_back(existing->tile->buffer); // reuse buffer from already queued job
234+
continue;
235+
}
236+
228237
CachedTile *tileToReplace = findUnusedTile(requiredTiles, zoom);
229238
if (!tileToReplace)
230239
{
231240
tilePointers.push_back(nullptr); // again, keep 1:1 aligned
232241
continue;
233242
}
234243

235-
tilePointers.push_back(tileToReplace->buffer); // push_back the still-to-download tile ptr
236-
jobs.push_back({x, static_cast<uint32_t>(y), zoom, tileToReplace}); // push_back tile ptr to the job list
244+
tilePointers.push_back(tileToReplace->buffer); // store buffer for rendering
245+
jobs.push_back({x, static_cast<uint32_t>(y), zoom, tileToReplace}); // queue job
237246
}
238247
}
239248

0 commit comments

Comments
 (0)