diff --git a/include/mbgl/style/sources/geojson_source.hpp b/include/mbgl/style/sources/geojson_source.hpp index 4b53b6f16..30b3344e2 100644 --- a/include/mbgl/style/sources/geojson_source.hpp +++ b/include/mbgl/style/sources/geojson_source.hpp @@ -82,6 +82,7 @@ protected: private: std::optional url; std::unique_ptr req; + std::atomic requestGeneration{0}; std::shared_ptr sequencedScheduler; mapbox::base::WeakPtrFactory weakFactory{this}; // Do not add members here, see `WeakPtrFactory` diff --git a/src/mbgl/style/sources/geojson_source.cpp b/src/mbgl/style/sources/geojson_source.cpp index afc65d71e..29319255a 100644 --- a/src/mbgl/style/sources/geojson_source.cpp +++ b/src/mbgl/style/sources/geojson_source.cpp @@ -99,10 +99,12 @@ void GeoJSONSource::loadDescription(FileSource& fileSource) { return makeMutable(current, std::move(geoJSONData)); }, /* onImplReady */ - [this, self = makeWeakPtr(), capturedReq = req.get()](Immutable newImpl) { - assert(capturedReq); + [this, self = makeWeakPtr(), capturedReqGeneration = ++requestGeneration]( + Immutable newImpl) { + assert(capturedReqGeneration); if (auto guard = self.lock(); self) { - if (capturedReq == req.get()) { // If a new request is being processed, ignore this impl. + if (capturedReqGeneration == + requestGeneration) { // If a new request is being processed, ignore this impl. baseImpl = std::move(newImpl); loaded = true; observer->onSourceLoaded(*this);