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

Copy features array before passing them to core #14804

Merged
merged 1 commit into from
Jun 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,21 @@ public void setGeoJson(Geometry geometry) {
* Updates the GeoJson. The update is performed asynchronously,
* so the data won't be immediately visible or available to query when this method returns.
*
* @param features the GeoJSON FeatureCollection
* @param featureCollection the GeoJSON FeatureCollection
*/
public void setGeoJson(FeatureCollection features) {
public void setGeoJson(FeatureCollection featureCollection) {
if (detached) {
return;
}
checkThread();
nativeSetFeatureCollection(features);

List<Feature> features = featureCollection.features();
if (features != null) {
List<Feature> featuresCopy = new ArrayList<>(features);
nativeSetFeatureCollection(FeatureCollection.fromFeatures(featuresCopy));
} else {
nativeSetFeatureCollection(featureCollection);
}
}

/**
Expand Down Expand Up @@ -445,7 +452,7 @@ public FeatureCollection getClusterChildren(@NonNull Feature cluster) {
* </p>
*
* @param cluster cluster from which to retrieve leaves from
* @param limit limit is the number of points to return
* @param limit limit is the number of points to return
* @param offset offset is the amount of points to skip (for pagination)
* @return a list of features for the underlying leaves
*/
Expand Down Expand Up @@ -497,10 +504,10 @@ public int getClusterExpansionZoom(@NonNull Feature cluster) {
private native Feature[] querySourceFeatures(Object[] filter);

@Keep
private native Feature[] nativeGetClusterChildren(Feature feature);
private native Feature[] nativeGetClusterChildren(Feature feature);

@Keep
private native Feature[] nativeGetClusterLeaves(Feature feature, long limit, long offset);
private native Feature[] nativeGetClusterLeaves(Feature feature, long limit, long offset);

@Keep
private native int nativeGetClusterExpansionZoom(Feature feature);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.junit.runner.RunWith;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import timber.log.Timber;

Expand Down Expand Up @@ -101,6 +103,22 @@ public void testUpdateCoalescing() {
});
}

@Test
public void testClearCollectionDuringConversion() {
// https://github.com/mapbox/mapbox-gl-native/issues/14565
validateTestSetup();
MapboxMapAction.invoke(mapboxMap, (uiController, mapboxMap) -> {
for (int j = 0; j < 1000; j++) {
List<Feature> features = new ArrayList<>();
for (int i = 0; i < 100; i++) {
features.add(Feature.fromGeometry(Point.fromLngLat(0, 0)));
}
mapboxMap.getStyle().addSource(new GeoJsonSource("source" + j, FeatureCollection.fromFeatures(features)));
features.clear();
}
});
}

@Test
public void testPointFeature() {
testFeatureFromResource(R.raw.test_point_feature);
Expand Down