Skip to content

Prevent duplicate tile fetch jobs #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/OpenStreetMap-esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,24 @@ void OpenStreetMap::makeJobList(const tileList &requiredTiles, std::vector<TileJ
if (isTileCached(x, y, zoom, tilePointers)) // isTileCached will push_back a valid ptr if tile is cached
continue;

// Check if this tile is already in the job list
auto existing = std::find_if(jobs.begin(), jobs.end(), [&](const TileJob &job)
{ return job.x == x && job.y == static_cast<uint32_t>(y) && job.z == zoom; });
if (existing != jobs.end())
{
tilePointers.push_back(existing->tile->buffer); // reuse buffer from already queued job
continue;
}

CachedTile *tileToReplace = findUnusedTile(requiredTiles, zoom);
if (!tileToReplace)
{
tilePointers.push_back(nullptr); // again, keep 1:1 aligned
continue;
}

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

Expand Down