[Android] Native Crash
Platform:Android Mapbox SDK version:5.3.1
Steps to trigger behavior
1.build mapbox sdk on branch release-agua commit 2478942
# GLThread 8181(8181)
SIGSEGV(SEGV_MAPERR)
#00 pc 00303814 libmapbox-gl.so placeGlyphsAlongLine (/Users/di.duan/Documents/DEV/mapbox-gl-native/src/mbgl/layout/symbol_projection.cpp:293) [armeabi-v7a]
#01 pc 00303bfb libmapbox-gl.so reprojectLineLabels (/Users/di.duan/Documents/DEV/mapbox-gl-native/src/mbgl/layout/symbol_projection.cpp:349) [armeabi-v7a]
#02 pc 002c07df libmapbox-gl.so render (/Users/di.duan/Documents/DEV/mapbox-gl-native/src/mbgl/renderer/layers/render_symbol_layer.cpp:193) [armeabi-v7a]
#03 pc 001dd0d9 libmapbox-gl.so render (/Users/di.duan/Documents/DEV/mapbox-gl-native/src/mbgl/renderer/renderer_impl.cpp:546) [armeabi-v7a]
#04 pc 001da91b libmapbox-gl.so render (/Users/di.duan/Documents/DEV/mapbox-gl-native/src/mbgl/renderer/renderer.cpp:33) [armeabi-v7a]
#05 pc 00071249 libmapbox-gl.so render (/Users/di.duan/Documents/DEV/mapbox-gl-native/platform/android/src/map_renderer.cpp:136) [armeabi-v7a]
#06 pc 00072b89 libmapbox-gl.so __invoke (../../../../../../../mason_packages/headers/jni.hpp/3.0.0/include/jni/native_method.hpp:110 [Inline: operator()]) [armeabi-v7a]
#07 pc 00072bcd libmapbox-gl.so __invoke<jni::jobject *> (../../../../../../../mason_packages/headers/jni.hpp/3.0.0/include/jni/native_method.hpp:59) [armeabi-v7a]
#08 pc 0256912f /data/app/com.moji.mjweather-1/oat/arm/base.odex (oatexec+9294127) [armeabi]
java:
com.mapbox.mapboxsdk.maps.renderer.MapRenderer.void onDrawFrame(javax.microedition.khronos.opengles.GL10)(MapRenderer.java:90)
com.mapbox.mapboxsdk.maps.renderer.glsurfaceview.GLSurfaceViewMapRenderer.void onDrawFrame(javax.microedition.khronos.opengles.GL10)(GLSurfaceViewMapRenderer.java:55)
android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1535)
android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
another stack
# Thread-1206(15893)
SIGSEGV(SEGV_MAPERR)
#00 pc 00303814 libmapbox-gl.so placeGlyphsAlongLine (/Users/di.duan/Documents/DEV/mapbox-gl-native/src/mbgl/layout/symbol_projection.cpp:293) [armeabi-v7a]
#01 pc 00303bfb libmapbox-gl.so reprojectLineLabels (/Users/di.duan/Documents/DEV/mapbox-gl-native/src/mbgl/layout/symbol_projection.cpp:349) [armeabi-v7a]
#02 pc 002c07df libmapbox-gl.so render (/Users/di.duan/Documents/DEV/mapbox-gl-native/src/mbgl/renderer/layers/render_symbol_layer.cpp:193) [armeabi-v7a]
#03 pc 001dd0d9 libmapbox-gl.so render (/Users/di.duan/Documents/DEV/mapbox-gl-native/src/mbgl/renderer/renderer_impl.cpp:546) [armeabi-v7a]
#04 pc 001da91b libmapbox-gl.so render (/Users/di.duan/Documents/DEV/mapbox-gl-native/src/mbgl/renderer/renderer.cpp:33) [armeabi-v7a]
#05 pc 00071249 libmapbox-gl.so render (/Users/di.duan/Documents/DEV/mapbox-gl-native/platform/android/src/map_renderer.cpp:136) [armeabi-v7a]
#06 pc 00072b89 libmapbox-gl.so __invoke (../../../../../../../mason_packages/headers/jni.hpp/3.0.0/include/jni/native_method.hpp:110 [Inline: operator()]) [armeabi-v7a]
#07 pc 00072bcd libmapbox-gl.so __invoke<jni::jobject *> (../../../../../../../mason_packages/headers/jni.hpp/3.0.0/include/jni/native_method.hpp:59) [armeabi-v7a]
#08 pc 0001eb8c /system/lib/libdvm.so (dvmPlatformInvoke+112) [armeabi-v7a]
#09 pc 0004f253 /system/lib/libdvm.so (dvmCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+398) [armeabi-v7a]
#10 pc 00027fa0 /system/lib/libdvm.so [armeabi-v7a]
#11 pc 0002f110 /system/lib/libdvm.so (dvmMterpStd(Thread*)+76) [armeabi-v7a]
#12 pc 0002c774 /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+184) [armeabi-v7a]
#13 pc 00061705 /system/lib/libdvm.so (dvmCallMethodV(Thread*, Method const*, Object*, bool, JValue*, std::__va_list)+336) [armeabi-v7a]
#14 pc 00061729 /system/lib/libdvm.so (dvmCallMethod(Thread*, Method const*, Object*, JValue*, ...)+20) [armeabi-v7a]
#15 pc 00056423 /system/lib/libdvm.so [armeabi-v7a]
#16 pc 0000d408 /system/lib/libc.so (__thread_entry+72) [armeabi-v7a]
#17 pc 0000d5a0 /system/lib/libc.so (pthread_create+240) [armeabi-v7a]
java:
com.mapbox.mapboxsdk.maps.renderer.MapRenderer.void nativeRender()(Native Method)
com.mapbox.mapboxsdk.maps.renderer.MapRenderer.void onDrawFrame(javax.microedition.khronos.opengles.GL10)(MapRenderer.java:90)
com.mapbox.mapboxsdk.maps.renderer.textureview.TextureViewMapRenderer.void onDrawFrame(javax.microedition.khronos.opengles.GL10)(TextureViewMapRenderer.java:56)
com.mapbox.mapboxsdk.maps.renderer.textureview.TextureViewRenderThread.void run()(TextureViewRenderThread.java:282)
@cmxyzx can you provide a step by step case to reproduce this crash?
@tobrun sorry, we can't get step by step case to reproduce this issue for now. The stack is collected from online crash reporting like fabric. Reproduced with 20 users in 30,000 canary release users.
We will try to do more test our side to find the step by step case.
@tobrun We found this issue may related with font When using this setting
app:mapbox_localIdeographFontFamily="CJK Unified Ideographs"
the crash happens when frequently zoom in and zoom out
When remove the font setting, carsh can not be reproduced
mapview configuration as below
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/map_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:mapbox_apiBaseUrl="https://api.mapbox.cn"
app:mapbox_localIdeographFontFamily="CJK Unified Ideographs"
app:mapbox_styleUrl="mapbox://styles/mapbox/streets-zh-v1"
app:mapbox_uiAttribution="false"
app:mapbox_uiLogo="false" />
@ChrisLoer is the stacktrace in OP actionable? If not I can try reproducing locally and symbolicate the trace.
@tobrun The specified commit https://github.com/mapbox/mapbox-gl-native/commit/2478942 is on a development branch, not release-agua -- but looking at release-agua, the stack trace looks pretty informative. It's pointing to an assertion that basically says we should have a glyph for every character in the text, and there can be a crash if that assertion is violated. I've been looking and I haven't found a hole in the logic yet, but this crash report is a good hint that there's a problem to find here. I'll keep looking.
@cmxyzx It shouldn't matter but app:mapbox_localIdeographFontFamily="CJK Unified Ideographs" is a strange value for the setting -- the setting expects the name of a font family (like "Droid Sans"), and "CJK Unified Ideographs" is the name of a Unicode block, not the name of any font I know of. However, when it sees an unknown font, it should just use the default system font, which should work OK.
I have found one potential hole in the logic, which is that BiDi::processText can potentially modify the set of glyphs in a label after we've requested glyphs. If that happened, it could cause this crash, although I think it would be very unlikely (it would require a label that consisted of just an RTL marker and a "mirrorable" glyph). Also I don't see an obvious connection between this and localIdeographFontFamily.
In GlyphManager, if we get a glyph PBF back that doesn't have a glyph we've requested, we put a "null" entry in the GlyphMap:
https://github.com/mapbox/mapbox-gl-native/blob/082df681c866466b8a69bf27cbb42b01eed7f5e1/src/mbgl/text/glyph_manager.cpp#L137-L140
Then, in makeGlyphAtlas, we filter out glyphs that have null glyph entries:
https://github.com/mapbox/mapbox-gl-native/blob/082df681c866466b8a69bf27cbb42b01eed7f5e1/src/mbgl/text/glyph_atlas.cpp#L21
Then, in getGlyphQuads, we filter out symbols that don't have a matching entry in the glyph atlas:
https://github.com/mapbox/mapbox-gl-native/blob/082df681c866466b8a69bf27cbb42b01eed7f5e1/src/mbgl/text/quads.cpp#L107-L110
The expected behavior is that we just won't render anything in the place of the missing glyph. This however breaks our assumption at:
https://github.com/mapbox/mapbox-gl-native/blob/082df681c866466b8a69bf27cbb42b01eed7f5e1/src/mbgl/layout/symbol_projection.cpp#L340-L341
This crash would be triggered whenever the map tried to render a label in which all of the characters in a label were unavailable in the chosen font stack. This crash should be easy to avoid just by adding a condition to handle the case symbol.glyphOffsets.size() == 0.
I don't have a good idea for why this crash would be triggered by the localIdeographFontFamily setting because when that functionality is being used, a Glyph is always returned (even if the system can't render anything, we'll just return a blank square for the character). Is it definitely the same crash as the one that was seen in the field?
@ChrisLoer we are using "CJK Unified Ideographs" intentionally to load the system font so that we can reduce the map loading time.
I will check the crash stack when using localIdeographFontFamily setting later to make it more specific
@ChrisLoer @tobrun Sorry this issue is not related with localIdeographFontFamily .
We have reproduced this issue without the localIdeographFontFamily configuration.
But still crashes with the below stacktrace
If we have the solution to avoid this crash, Is there any roadmap for version release?
I update the build on branch release-agua with commit 3f7c30f9d
********** Crash dump: **********
Build fingerprint: 'HUAWEI/MHA-AL00/HWMHA:8.0.0/HUAWEIMHA-AL00/342(C00):user/release-keys'
pid: 28079, tid: 28204, name: GLThread 1054 >>> di.duan.demo.mapbox <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
Stack frame #00 pc 0000000000426920 /data/app/di.duan.demo.mapbox-8NGV1ujVzuB9fuDNT4YbIA==/lib/arm64/libmapbox-gl.so: Routine mbgl::placeGlyphsAlongLine(mbgl::PlacedSymbol const&, float, bool, bool, std::__ndk1::array<double, 16ul> const&, std::__ndk1::array<double, 16ul> const&, std::__ndk1::array<double, 16ul> const&, mbgl::gl::VertexVector<mbgl::gl::detail::Vertex<mbgl::gl::Attribute<float, 3ul> >, mbgl::gl::Indexed>&, mapbox::geometry::point<float> const&) at /Users/di.duan/Documents/DEV/mapbox-gl-native/src/mbgl/layout/symbol_projection.cpp:293
Stack frame #01 pc 0000000000426de4 /data/app/di.duan.demo.mapbox-8NGV1ujVzuB9fuDNT4YbIA==/lib/arm64/libmapbox-gl.so: Routine mbgl::reprojectLineLabels(mbgl::gl::VertexVector<mbgl::gl::detail::Vertex<mbgl::gl::Attribute<float, 3ul> >, mbgl::gl::Indexed>&, std::__ndk1::vector<mbgl::PlacedSymbol, std::__ndk1::allocator<mbgl::PlacedSymbol> > const&, std::__ndk1::array<double, 16ul> const&, mbgl::style::SymbolPropertyValues const&, mbgl::RenderTile const&, mbgl::SymbolSizeBinder const&, mbgl::TransformState const&, mbgl::FrameHistory const&) at /Users/di.duan/Documents/DEV/mapbox-gl-native/src/mbgl/layout/symbol_projection.cpp:349
Stack frame #02 pc 00000000003c3c04 /data/app/di.duan.demo.mapbox-8NGV1ujVzuB9fuDNT4YbIA==/lib/arm64/libmapbox-gl.so: Routine mbgl::RenderSymbolLayer::render(mbgl::PaintParameters&, mbgl::RenderSource*) at /Users/di.duan/Documents/DEV/mapbox-gl-native/src/mbgl/renderer/layers/render_symbol_layer.cpp:193
Stack frame #03 pc 000000000027f768 /data/app/di.duan.demo.mapbox-8NGV1ujVzuB9fuDNT4YbIA==/lib/arm64/libmapbox-gl.so: Routine mbgl::Renderer::Impl::render(mbgl::UpdateParameters const&) at /Users/di.duan/Documents/DEV/mapbox-gl-native/src/mbgl/renderer/renderer_impl.cpp:546
Stack frame #04 pc 00000000000b2598 /data/app/di.duan.demo.mapbox-8NGV1ujVzuB9fuDNT4YbIA==/lib/arm64/libmapbox-gl.so: Routine mbgl::android::MapRenderer::render(_JNIEnv&) at /Users/di.duan/Documents/DEV/mapbox-gl-native/platform/android/src/map_renderer.cpp:136
Stack frame #05 pc 00000000000b4aa0 /data/app/di.duan.demo.mapbox-8NGV1ujVzuB9fuDNT4YbIA==/lib/arm64/libmapbox-gl.so: Routine operator() at /Users/di.duan/Documents/DEV/mapbox-gl-native/platform/android/MapboxGLAndroidSDK/.externalNativeBuild/cmake/release/arm64-v8a/../../../../../../../mason_packages/headers/jni.hpp/3.0.0/include/jni/native_method.hpp:245
Stack frame #06 pc 00000000000b4af0 /data/app/di.duan.demo.mapbox-8NGV1ujVzuB9fuDNT4YbIA==/lib/arm64/libmapbox-gl.so: Routine operator()<jni::jobject *> at /Users/di.duan/Documents/DEV/mapbox-gl-native/platform/android/MapboxGLAndroidSDK/.externalNativeBuild/cmake/release/arm64-v8a/../../../../../../../mason_packages/headers/jni.hpp/3.0.0/include/jni/native_method.hpp:59
Stack frame #07 pc 000000000001904c /data/app/di.duan.demo.mapbox-8NGV1ujVzuB9fuDNT4YbIA==/oat/arm64/base.odex (offset 0xf000)
@cmxyzx Thanks for narrowing that down! I'm glad you could reproduce without the setting because I didn't have an explanation for why the setting would cause the crash.
I pushed a simple fix to the crash at https://github.com/mapbox/mapbox-gl-native/tree/cloer-10956. The branch is from master, but you can see the change is very simple and could be cherry-picked onto the release-agua branch too. It's a little bit speculative -- I'm not sure I understand the true root cause. However, if you apply the patch to your build and can't reproduce the crash, that would be a good sign. I will be back in the office next week and able to spend more time looking at it.
My analysis in https://github.com/mapbox/mapbox-gl-native/issues/10956#issuecomment-360910727 was a little bit off, but with a little tweak I think it's a strong hypothesis for what's going wrong. At first, I thought the problem would show up if we got a GlyphPBF that didn't include a certain Glyph. But that case would be handled here:
https://github.com/mapbox/mapbox-gl-native/blob/90f29a91729b536da9f090d389549db1ec4b8e9f/src/mbgl/text/shaping.cpp#L284-L286
The !it->second part tests for null Glyph entries. However, the case that we don't check for is valid Glyph entries with invalid bitmap members. It turns out there are a fair number of those, because we consider a bitmap with a size of 0 to be invalid. For instance in Arial Unicode:
GlyphID: 32 (' ') has size 0
GlyphID: 160 (' ') has size 0
GlyphID: 3975 ('྇') has size 0
GlyphID: 8192 (' ') has size 0
GlyphID: 8193 (' ') has size 0
GlyphID: 8194 (' ') has size 0
GlyphID: 8195 (' ') has size 0
GlyphID: 8196 (' ') has size 0
GlyphID: 8197 (' ') has size 0
GlyphID: 8198 (' ') has size 0
GlyphID: 8199 (' ') has size 0
GlyphID: 8200 (' ') has size 0
GlyphID: 8201 (' ') has size 0
GlyphID: 8202 (' ') has size 0
GlyphID: 8203 ('') has size 0
GlyphID: 8204 ('') has size 0
GlyphID: 8205 ('') has size 0
GlyphID: 8232 ('
') has size 0
GlyphID: 8233 ('
') has size 0
GlyphID: 4447 ('ᅟ') has size 0
GlyphID: 4448 ('ᅠ') has size 0
GlyphID: 12644 ('ㅤ') has size 0
GlyphID: 12288 (' ') has size 0
The fix is the same -- although we might want to think about further changes to make this less of a pitfall.
@ChrisLoer Thanks for the detailed analysis. We have built and tested on the commit 055716d, no crash reproduced.
Will close this issue after verified on v5.4.1
Fixed in #11120. I'll follow up with cherry-pick PRs to the agua and boba release branches.