Skip to content

Commit

Permalink
🪲 Fix a potential race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Schneegans committed Mar 21, 2024
1 parent e7904f5 commit 5280a86
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion plugins/csp-lod-bodies/src/TreeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,13 @@ void TreeManager::request(std::vector<TileId> const& tileIds) {
// load the tile.
// In the case of async loading, register @c onDataLoaded as the callback
// that the source invokes when the tile is ready.
std::unique_lock<std::mutex> lck(mPendingMtx);

for (auto const& tileId : tileIds) {
mPendingMtx.lock();

if (mPendingTiles.count(tileId) == 0) {
mPendingTiles[tileId] = new TileNode(tileId);
mPendingMtx.unlock();

for (auto const& src : mTileDataSources.mChannels) {
if (src) {
Expand All @@ -138,6 +140,8 @@ void TreeManager::request(std::vector<TileId> const& tileIds) {
}
}
}
} else {
mPendingMtx.unlock();
}
}
}
Expand Down Expand Up @@ -344,6 +348,8 @@ void TreeManager::merge() {
for (std::size_t i = 0; i < mUnmergedNodes.size();) {
TileNode* node = mUnmergedNodes[i].mNode;

std::unique_lock<std::mutex> lck(mPendingMtx);

if (insertNode(&mTree, node)) {
// insert succeeded, remove from pending and unmerged and
// associate render data with node
Expand Down

0 comments on commit 5280a86

Please sign in to comment.