Fix segfault this-capture GeoJsonSource which may be deleted (#3536)
Co-authored-by: Tim Sylvester <tim@wetdogweather.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package org.maplibre.android.testapp.style;
|
||||
|
||||
import org.maplibre.android.style.sources.CannotAddSourceException;
|
||||
import org.maplibre.geojson.Feature;
|
||||
import org.maplibre.geojson.FeatureCollection;
|
||||
import org.maplibre.geojson.Point;
|
||||
@@ -155,6 +156,29 @@ public class GeoJsonSourceTests extends EspressoTest {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDuplicateSourceDuringAsyncSetGeoJson() {
|
||||
// regression test for segfault when setting GeoJSON contents
|
||||
// for a source that has been deleted
|
||||
// https://github.com/maplibre/maplibre-native/issues/3493
|
||||
validateTestSetup();
|
||||
MapLibreMapAction.invoke(maplibreMap, (uiController, maplibreMap) -> {
|
||||
String geoJsonString = "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[0,0]}}";
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
// Create a GeoJSON source with the same ID each iteration
|
||||
GeoJsonSource source = new GeoJsonSource("source");
|
||||
try {
|
||||
maplibreMap.getStyle().addSource(source);
|
||||
} catch (CannotAddSourceException ex) {
|
||||
// ignore, this is expected
|
||||
}
|
||||
|
||||
// Schedule an async update via setGeoJson(String)
|
||||
source.setGeoJson(geoJsonString);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public abstract class BaseViewAction implements ViewAction {
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user