This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Crash with FeatureIndex::addFeature while Map::queryPointAnnotations #8289
Copy link
Copy link
Closed
Labels
AndroidMapbox Maps SDK for AndroidcrashiOSMapbox Maps SDK for iOSrelease blockerBlocks the next final release
Milestone
Description
When looking to reproduce #8202 / #8275 by constantly calling Map::queryPointAnnotation(), I was able to produce the following symbolicated stacktrace:
********** Crash dump: **********
Build fingerprint: 'google/angler/angler:7.1.2/NPG05F/3729850:user/release-keys'
pid: 25377, tid: 25377, name: pboxsdk.testapp >>> com.mapbox.mapboxsdk.testapp <<<
signal 7 (SIGBUS), code 1 (BUS_ADRALN), fault addr 0x1000d
Stack frame #00 pc 0015d0bc /data/app/com.mapbox.mapboxsdk.testapp-2/lib/arm/libmapbox-gl.so: Routine std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >::__get_long_size() const at /Users/Nurbot/mapbox-gl-native/mason_packages/osx-x86_64/android-ndk/arm-v7-9-r13b/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../include/c++/4.9.x/string:1797
Stack frame #01 pc 0015d015 /data/app/com.mapbox.mapboxsdk.testapp-2/lib/arm/libmapbox-gl.so: Routine AnnotationTileFeature at /Users/Nurbot/mapbox-gl-native/build/android-arm-v7-9/Debug/../../../src/mbgl/annotation/annotation_tile.hpp:27
Stack frame #02 pc 0016a461 /data/app/com.mapbox.mapboxsdk.testapp-2/lib/arm/libmapbox-gl.so: Routine mbgl::FeatureIndex::addFeature(std::__ndk1::unordered_map<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >, std::__ndk1::vector<mapbox::geometry::feature<double>, std::__ndk1::allocator<mapbox::geometry::feature<double> > >, std::__ndk1::hash<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > >, std::__ndk1::equal_to<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > >, std::__ndk1::allocator<std::__ndk1::pair<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const, std::__ndk1::vector<mapbox::geometry::feature<double>, std::__ndk1::allocator<mapbox::geometry::feature<double> > > > > >&, mbgl::IndexedSubfeature const&, mbgl::GeometryCoordinates const&, std::experimental::fundamentals_v1::optional<std::__ndk1::vector<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >, std::__ndk1::allocator<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > > > > const&, mbgl::GeometryTileData const&, mbgl::CanonicalTileID const&, mbgl::style::Style const&, float, float) const at /Users/Nurbot/mapbox-gl-native/src/mbgl/geometry/feature_index.cpp:113 (discriminator 1)
Stack frame #03 pc 0016a363 /data/app/com.mapbox.mapboxsdk.testapp-2/lib/arm/libmapbox-gl.so: Routine mbgl::FeatureIndex::query(std::__ndk1::unordered_map<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >, std::__ndk1::vector<mapbox::geometry::feature<double>, std::__ndk1::allocator<mapbox::geometry::feature<double> > >, std::__ndk1::hash<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > >, std::__ndk1::equal_to<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > >, std::__ndk1::allocator<std::__ndk1::pair<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const, std::__ndk1::vector<mapbox::geometry::feature<double>, std::__ndk1::allocator<mapbox::geometry::feature<double> > > > > >&, mbgl::GeometryCoordinates const&, float, double, double, std::experimental::fundamentals_v1::optional<std::__ndk1::vector<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >, std::__ndk1::allocator<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > > > > const&, mbgl::GeometryTileData const&, mbgl::CanonicalTileID const&, mbgl::style::Style const&, mbgl::CollisionTile const*) const at /Users/Nurbot/mapbox-gl-native/src/mbgl/geometry/feature_index.cpp:90
Stack frame #04 pc 001d2075 /data/app/com.mapbox.mapboxsdk.testapp-2/lib/arm/libmapbox-gl.so: Routine mbgl::GeometryTile::queryRenderedFeatures(std::__ndk1::unordered_map<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >, std::__ndk1::vector<mapbox::geometry::feature<double>, std::__ndk1::allocator<mapbox::geometry::feature<double> > >, std::__ndk1::hash<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > >, std::__ndk1::equal_to<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > >, std::__ndk1::allocator<std::__ndk1::pair<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const, std::__ndk1::vector<mapbox::geometry::feature<double>, std::__ndk1::allocator<mapbox::geometry::feature<double> > > > > >&, mbgl::GeometryCoordinates const&, mbgl::TransformState const&, std::experimental::fundamentals_v1::optional<std::__ndk1::vector<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >, std::__ndk1::allocator<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > > > > const&) at /Users/Nurbot/mapbox-gl-native/src/mbgl/tile/geometry_tile.cpp:148
Stack frame #05 pc 000b8e73 /data/app/com.mapbox.mapboxsdk.testapp-2/lib/arm/libmapbox-gl.so: Routine mbgl::style::Source::Impl::queryRenderedFeatures(mbgl::style::QueryParameters const&) const at /Users/Nurbot/mapbox-gl-native/src/mbgl/style/source_impl.cpp:246
Stack frame #06 pc 000bd071 /data/app/com.mapbox.mapboxsdk.testapp-2/lib/arm/libmapbox-gl.so: Routine mbgl::style::Style::queryRenderedFeatures(mbgl::style::QueryParameters const&) const at /Users/Nurbot/mapbox-gl-native/src/mbgl/style/style.cpp:523
Stack frame #07 pc 0009d5a9 /data/app/com.mapbox.mapboxsdk.testapp-2/lib/arm/libmapbox-gl.so: Routine mbgl::Map::queryRenderedFeatures(mapbox::geometry::box<double> const&, std::experimental::fundamentals_v1::optional<std::__ndk1::vector<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >, std::__ndk1::allocator<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > > > > const&) at /Users/Nurbot/mapbox-gl-native/src/mbgl/map/map.cpp:826 (discriminator 1)
Stack frame #08 pc 0009d6d3 /data/app/com.mapbox.mapboxsdk.testapp-2/lib/arm/libmapbox-gl.so: Routine mbgl::Map::queryPointAnnotations(mapbox::geometry::box<double> const&) at /Users/Nurbot/mapbox-gl-native/src/mbgl/map/map.cpp:840 (discriminator 3)
Stack frame #09 pc 00073283 /data/app/com.mapbox.mapboxsdk.testapp-2/lib/arm/libmapbox-gl.so: Routine mbgl::android::NativeMapView::queryPointAnnotations(_JNIEnv&, jni::Object<mbgl::android::RectF>) at /Users/Nurbot/mapbox-gl-native/platform/android/src/native_map_view.cpp:704 (discriminator 2)
Stack frame #10 pc 00088193 /data/app/com.mapbox.mapboxsdk.testapp-2/lib/arm/libmapbox-gl.so: Routine operator()<jni::jobject *, jni::jobject *> at /Users/Nurbot/mapbox-gl-native/build/android-arm-v7-9/Debug/../../../mason_packages/headers/jni.hpp/3.0.0/include/jni/native_method.hpp:59
Stack frame #11 pc 00525705 /data/app/com.mapbox.mapboxsdk.testapp-2/oat/arm/base.odex (offset 0x4fc000)Been trying to produce this with a core gl test, but so far no luck.
Metadata
Metadata
Assignees
Labels
AndroidMapbox Maps SDK for AndroidcrashiOSMapbox Maps SDK for iOSrelease blockerBlocks the next final release
Activity
ncryu2 commentedon Mar 9, 2017
I don't know this is the same problem, but crash on ios v3.4.1
malloc: *** mach_vm_map(size=4506811913453568) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
libc++abi.dylib: terminating with uncaught exception of type std::bad_alloc: std::bad_alloc
ivovandongen commentedon Mar 9, 2017
This seems to be a duplicate of #8202 and can be reproduced fairly consistently on some devices (Moto X 2nd generation) with #8202 (comment).
There are two issues that are causing crashes. One is that the
GeometryTileDatamember ofGeometryTilepassed toFeatureIndex::queryRenderedFeaturesis invalid sometimes under heavy load. Reordering the members ofGeometryTileso that data (GeometryTileData) is destructed after the FeatureIndex resolves this crash:The other problem seems to be that the indices in
FeatureIndexpassed to AnnotationTileLayer::getFeature() are sometimes out of bounds under high load (verified with an assertion). Which leads to:This seems to be the same as #8289 (comment) on iOS.
cc @kkaefer
ivovandongen commentedon Mar 9, 2017
Debugging some more, it seem we might be accessing the
GeometryTileDatafrom multiple threads concurrently:(Note the "Worker 2" and "pboxsdk.testapp" (main) thread)
jfirebaugh commentedon Mar 9, 2017
GeometryTileData, the class, is used on both the main thread and on worker threads, but individual instances aren't accessed concurrently.I think the issue here is somehow feature indexes are getting into the
FeatureIndexthat are out of bounds for the vector of features held by theAnnotationTileLayer. Not sure how that happens though.ivovandongen commentedon Mar 10, 2017
Digging into why the index in
FeatureIndexdoesn't match up with with the indices inAnnotationTileLayerit seems that there is a moment betweenAnnotationManager::updateAnnotationand redoing the layout where this might occur.ivovandongen commentedon Mar 13, 2017
The actual problem lies in a mismatch between the
GeometryTileDataandCollisionTileonGeometryTileand stems from the fact that both are not updated atomically.The updating of both happens in GeometryTileWorker::redoLayout() where first
GeometryTile#onLayoutis called (which setsGeometryTileData) asynchronously and thenGeometryTile#onPlacement(which sets theCollisionTile) afterGeometryTileWorker#attemptPlacementcompletes.In GeometryTile::queryRenderedFeatures the
GeometryTileDataandCollisionTileare passed toFeatureIndex::query. Here theCollisionTileis used to lookup theIndexedSubFeatureswhich are used in FeatureIndex::addFeature to get the actual Feature from theGeometryTileLayerretrieved from theGeometryTileDataThis goes wrong when the worker has called
GeometryTile::onLayoutafter an Annotation is updated and crosses tile boundaries, butGeometryTile::onPlacementis not yet called whenGeometryTile::queryRenderedFeaturesis called. In this case the newGeometryTileDataand the oldCollisionTileare passed toFeatureIndex::querypossibly causing an out of bounds error in AnnotationTileLayer::getFeature because the bounds of the vector are not checked (assumed to be correct)jfirebaugh commentedon Mar 13, 2017
Nice work tracking that down @ivovandongen. It hadn't occurred to me that the issue could be the
GeometryTileDataandCollisionTilegetting out of sync. Will comment on the PR with some further thoughts.