Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Avoid binding a shared_ptr<TileData> in the work callback
Browse files Browse the repository at this point in the history
It's possible that the work callback can outlive the after callback,
since work callback destruction and after callback execution happen in
two different threads. This could account for the crash seen in
#1309 (comment)
  • Loading branch information
jfirebaugh committed Apr 28, 2015
1 parent cdb466e commit 2c3952a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/mbgl/map/tile_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ void TileData::cancel() {
void TileData::reparse(Worker& worker, std::function<void()> callback) {
util::ptr<TileData> tile = shared_from_this();
worker.send(
[tile]() {
EnvironmentScope scope(tile->env, ThreadType::TileWorker, "TileWorker_" + tile->name);
tile->parse();
[this]() {
EnvironmentScope scope(env, ThreadType::TileWorker, "TileWorker_" + name);
parse();
},
[tile, callback]() {
// `tile` is bound in this lambda to ensure that if it's the last owning pointer,
// destruction happens on the map thread, not the worker thread.
// destruction happens on the map thread, not the worker thread. It is _not_ bound
// in the above lambda, because we do not want the possibility to arise that the
// after callback could execute and release the penultimate reference before the
// work callback has been destructed.
callback();
});
}

0 comments on commit 2c3952a

Please sign in to comment.