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:
Bart Louwers
2025-06-06 23:38:19 +02:00
committed by GitHub
parent f6de3bc0e9
commit b0e2e2ce85
11 changed files with 96 additions and 46 deletions

View File

@@ -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