Avoid binding a shared_ptr<TileData> in the work callback
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 https://github.com/mapbox/mapbox-gl-native/issues/1309#issuecomment-96108868
This commit is contained in:
@@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user