summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Crocker <jesse@gaiagps.com>2017-03-06 09:59:00 -0700
committerJesse Crocker <jesse@gaiagps.com>2017-03-06 09:59:00 -0700
commit4bb3a9c58ca3beb8ab695ae66456cf9c4d9847d4 (patch)
tree8f1b7b81f1721cca2144f115cd0feb464680b5fb
parent86ab2880ca35091ca9f25e9279792fb5569ffaf8 (diff)
downloadqtlocation-mapboxgl-upstream/feature/custom-vector-source.tar.gz
Fix crash when source is deallocedupstream/feature/custom-vector-source
-rw-r--r--platform/darwin/src/MGLComputedShapeSource.mm30
-rw-r--r--src/mbgl/style/sources/custom_vector_source.cpp16
2 files changed, 25 insertions, 21 deletions
diff --git a/platform/darwin/src/MGLComputedShapeSource.mm b/platform/darwin/src/MGLComputedShapeSource.mm
index b4e4a6c54a..7eeea58f6c 100644
--- a/platform/darwin/src/MGLComputedShapeSource.mm
+++ b/platform/darwin/src/MGLComputedShapeSource.mm
@@ -29,7 +29,10 @@
@property (nonatomic, readonly) uint8_t z;
@property (nonatomic, readonly) uint32_t x;
@property (nonatomic, readonly) uint32_t y;
-@property (nonatomic, readonly, weak) MGLComputedShapeSource *source;
+@property (nonatomic, assign) BOOL dataSourceImplementsFeaturesForTile;
+@property (nonatomic, assign) BOOL dataSourceImplementsFeaturesForBounds;
+@property (nonatomic, weak, nullable) id<MGLComputedShapeSourceDataSource> dataSource;
+@property (nonatomic, nullable) mbgl::style::CustomVectorSource *rawSource;
- (instancetype)initForSource:(MGLComputedShapeSource*)source z:(uint8_t)z x:(uint32_t)x y:(uint32_t)y;
@@ -43,7 +46,11 @@
_x = x;
_y = y;
_z = z;
- _source = source;
+ _dataSourceImplementsFeaturesForTile = source.dataSourceImplementsFeaturesForTile;
+ _dataSourceImplementsFeaturesForBounds = source.dataSourceImplementsFeaturesForBounds;
+ _dataSource = source.dataSource;
+ mbgl::style::CustomVectorSource *rawSource = (mbgl::style::CustomVectorSource *)source.rawSource;
+ _rawSource = rawSource;
return self;
}
@@ -53,16 +60,16 @@
}
NSArray<MGLShape <MGLFeature> *> *data;
- if(!self.source.dataSource) {
+ if(!self.dataSource) {
data = nil;
- } else if(self.source.dataSourceImplementsFeaturesForTile) {
- data = [self.source.dataSource featuresInTileAtX:self.x
+ } else if(self.dataSourceImplementsFeaturesForTile) {
+ data = [self.dataSource featuresInTileAtX:self.x
y:self.y
zoomLevel:self.z];
} else {
mbgl::CanonicalTileID tileID = mbgl::CanonicalTileID(self.z, self.x, self.y);
mbgl::LatLngBounds tileBounds = mbgl::LatLngBounds(tileID);
- data = [self.source.dataSource featuresInCoordinateBounds:MGLCoordinateBoundsFromLatLngBounds(tileBounds)
+ data = [self.dataSource featuresInCoordinateBounds:MGLCoordinateBoundsFromLatLngBounds(tileBounds)
zoomLevel:self.z];
}
@@ -74,14 +81,19 @@
featureCollection.push_back(geoJsonObject);
}
const auto geojson = mbgl::GeoJSON{featureCollection};
- dispatch_async(dispatch_get_main_queue(), ^{
- if(![self isCancelled] && self.source.rawSource) {
- self.source.rawSource->setTileData(self.z, self.x, self.y, geojson);
+ dispatch_sync(dispatch_get_main_queue(), ^{
+ if(![self isCancelled] && self.rawSource) {
+ self.rawSource->setTileData(self.z, self.x, self.y, geojson);
}
});
}
}
+- (void)cancel {
+ [super cancel];
+ self.rawSource = NULL;
+}
+
@end
@implementation MGLComputedShapeSource
diff --git a/src/mbgl/style/sources/custom_vector_source.cpp b/src/mbgl/style/sources/custom_vector_source.cpp
index 3a12c08f5e..55e7974a83 100644
--- a/src/mbgl/style/sources/custom_vector_source.cpp
+++ b/src/mbgl/style/sources/custom_vector_source.cpp
@@ -10,27 +10,19 @@ CustomVectorSource::CustomVectorSource(std::string id, GeoJSONOptions options, s
}
void CustomVectorSource::setTileData(uint8_t z, uint32_t x, uint32_t y, const mapbox::geojson::geojson& geoJSON) {
- if(impl != nullptr) {
- impl->setTileData(z, x, y, geoJSON);
- }
+ impl->setTileData(z, x, y, geoJSON);
}
void CustomVectorSource::reloadRegion(mbgl::LatLngBounds bounds, uint8_t z) {
- if(impl != nullptr) {
- impl->reloadRegion(bounds, z);
- }
+ impl->reloadRegion(bounds, z);
}
void CustomVectorSource::updateTile(uint8_t z, uint32_t x, uint32_t y) {
- if(impl != nullptr) {
- impl->updateTile(z, x, y);
- }
+ impl->updateTile(z, x, y);
}
void CustomVectorSource::reload() {
- if(impl != nullptr) {
- impl->reload();
- }
+ impl->reload();
}
} // namespace style