rnmapbox / maps

A Mapbox react native module for creating custom maps
MIT License
2.27k stars 848 forks source link

[ios] Random crashes at start for MapboxGL.SymbolLayer with MapboxGL.Images #1096

Closed mzu closed 4 years ago

mzu commented 4 years ago

Describe the bug MapboxGL.SymbolLayer with iconImage in style is causing a native exception on ios. I only encountered this for Release builds. Does not happen on every app start but when it happens it crashes immediately while loading the screen with a map view.

Log from the actual app I am working on:

Screenshot 2020-11-02 at 17 36 29
Crashed: com.apple.root.default-qos
0  libobjc.A.dylib                0x194703978 objc_msgSend + 24
1  CoreFoundation                 0x180517114 -[NSArray sortedArrayUsingComparator:] + 60
2  fellbase                       0x102a83774 -[RCTImageLoader imageURLLoaderForURL:] + 184 (RCTImageLoader.mm:184)
3  fellbase                       0x102a84828 -[RCTImageLoader _loadImageOrDataWithURLRequest:size:scale:resizeMode:priority:attribution:progressBlock:partialLoadBlock:completionBlock:] + 482 (RCTImageLoader.mm:482)
4  fellbase                       0x102a86b6c -[RCTImageLoader loadImageWithURLRequest:size:scale:clipped:resizeMode:priority:attribution:progressBlock:partialLoadBlock:completionBlock:] + 809 (RCTImageLoader.mm:809)
5  fellbase                       0x102a83fd8 -[RCTImageLoader loadImageWithURLRequest:size:scale:clipped:resizeMode:priority:progressBlock:partialLoadBlock:completionBlock:] + 369 (RCTImageLoader.mm:369)
6  fellbase                       0x102a83eac -[RCTImageLoader loadImageWithURLRequest:size:scale:clipped:resizeMode:progressBlock:partialLoadBlock:completionBlock:] + 348 (RCTImageLoader.mm:348)
7  fellbase                       0x102beb684 __34-[RCTMGLImageQueueOperation start]_block_invoke + 113 (RCTMGLImageQueueOperation.m:113)
8  libdispatch.dylib              0x180216fd0 _dispatch_call_block_and_release + 32
9  libdispatch.dylib              0x180218ac8 _dispatch_client_callout + 20
10 libdispatch.dylib              0x18021ba10 _dispatch_queue_override_invoke + 692
11 libdispatch.dylib              0x180229104 _dispatch_root_queue_drain + 356
12 libdispatch.dylib              0x1802298e8 _dispatch_worker_thread2 + 116
13 libsystem_pthread.dylib        0x1c850b8cc _pthread_wqthread + 216
14 libsystem_pthread.dylib        0x1c851277c start_wqthread + 8

To Reproduce Here is a minimal version to reproduce the crash.

Two things seem to be mandatory to reproduce this:

  1. It only seems to happen for release builds

    Screenshot 2020-11-02 at 17 20 08
  2. There needs to be more than one element in the array for mapIcons:

    <MapboxGL.Images images={mapIcons} />

The crash happens at random when the component gets mounted. I had to shutdown the app completely (swipe up) and restart. After 10-20 tries the app normally crashes.

Versions (please complete the following information):

Please let me know if there is anything else you need in order to pin this one down.

mfazekas commented 4 years ago

@mzu thanks, for the detailed report.

What is the exact exception?! Also what are other threads are doing?! Especially the main thread?! I'd assume this is some threading issue, because we lazily init the react image loaders from non main thread.

mzu commented 4 years ago

@mfazekas I am using crashlytics to log the exception. Only the native exception handler provided a stack trace. The error was EXC_BAD_ACCESS KERN PROTECTION FAILURE. Some pointer issue?

The main thread shows the following:

com.apple.main-thread
0  GLEngine                       0x1b231246c glShaderSourceARB_Exec
1  GLEngine                       0x1b231243c glShaderSourceARB_Exec
2  Mapbox                         0x103fa2f30 mbgl::gl::Context::createShader(mbgl::gl::ShaderType, std::initializer_list<char const*> const&) + 100
3  Mapbox                         0x103fef818 mbgl::gl::Program<mbgl::LineProgram>::Instance::Instance(mbgl::gl::Context&, std::initializer_list<char const*> const&, std::initializer_list<char const*> const&) + 48
4  Mapbox                         0x103fee9a8 mbgl::gl::Program<mbgl::LineProgram>::Instance::createInstance(mbgl::gl::Context&, mbgl::ProgramParameters const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) + 256
5  Mapbox                         0x103fee5f8 mbgl::gl::Program<mbgl::LineProgram>::draw(mbgl::gfx::Context&, mbgl::gfx::RenderPass&, mbgl::gfx::DrawMode const&, mbgl::gfx::DepthMode const&, mbgl::gfx::StencilMode const&, mbgl::gfx::ColorMode const&, mbgl::gfx::CullFaceMode const&, mbgl::gfx::UniformValues<mbgl::TypeList<mbgl::uniforms::matrix, mbgl::uniforms::ratio, mbgl::uniforms::units_to_pixels, mbgl::uniforms::device_pixel_ratio, mbgl::InterpolationUniform<mbgl::attributes::blur>, mbgl::InterpolationUniform<mbgl::attributes::color>, mbgl::InterpolationUniform<mbgl::attributes::floorwidth>, mbgl::InterpolationUniform<mbgl::attributes::gapwidth>, mbgl::InterpolationUniform<mbgl::attributes::offset>, mbgl::InterpolationUniform<mbgl::attributes::opacity>, mbgl::InterpolationUniform<mbgl::attributes::pattern_to>, mbgl::InterpolationUniform<mbgl::attributes::pattern_from>, mbgl::InterpolationUniform<mbgl::attributes::width>, mbgl::uniforms::blur, mbgl::uniforms::color, mbgl::uniforms::floorwidth, mbgl::uniforms::gapwidth, mbgl::uniforms::offset, mbgl::uniforms::opacity, mbgl::uniforms::pattern_to, mbgl::uniforms::pattern_from, mbgl::uniforms::width> > const&, mbgl::gfx::DrawScope&, mbgl::gfx::AttributeBindings<mbgl::TypeList<mbgl::attributes::pos_normal, mbgl::attributes::data<unsigned char, 4ul>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::blur>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::color>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::floorwidth>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::gapwidth>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::offset>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::opacity>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::pattern_to>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::pattern_from>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::width> > > const&, mbgl::gfx::TextureBindings<mbgl::TypeList<> > const&, mbgl::gfx::IndexBuffer const&, unsigned long, unsigned long) + 364
6  Mapbox                         0x10404ac94 void mbgl::Program<mbgl::LineProgram, (mbgl::gfx::PrimitiveType)2, mbgl::TypeList<mbgl::attributes::pos_normal, mbgl::attributes::data<unsigned char, 4ul> >, mbgl::TypeList<mbgl::uniforms::matrix, mbgl::uniforms::ratio, mbgl::uniforms::units_to_pixels, mbgl::uniforms::device_pixel_ratio>, mbgl::TypeList<>, mbgl::style::LinePaintProperties>::draw<mbgl::gfx::Triangles>(mbgl::gfx::Context&, mbgl::gfx::RenderPass&, mbgl::gfx::Triangles const&, mbgl::gfx::DepthMode const&, mbgl::gfx::StencilMode const&, mbgl::gfx::ColorMode const&, mbgl::gfx::CullFaceMode const&, mbgl::gfx::IndexBuffer const&, std::__1::vector<mbgl::Segment<mbgl::TypeList<mbgl::attributes::pos_normal, mbgl::attributes::data<unsigned char, 4ul>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::blur>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::color>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::floorwidth>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::gapwidth>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::offset>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::opacity>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::pattern_to>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::pattern_from>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::width> > >, std::__1::allocator<mbgl::Segment<mbgl::TypeList<mbgl::attributes::pos_normal, mbgl::attributes::data<unsigned char, 4ul>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::blur>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::color>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::floorwidth>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::gapwidth>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::offset>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::opacity>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::pattern_to>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::pattern_from>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::width> > > > > const&, mbgl::gfx::UniformValues<mbgl::TypeList<mbgl::uniforms::matrix, mbgl::uniforms::ratio, mbgl::uniforms::units_to_pixels, mbgl::uniforms::device_pixel_ratio, mbgl::InterpolationUniform<mbgl::attributes::blur>, mbgl::InterpolationUniform<mbgl::attributes::color>, mbgl::InterpolationUniform<mbgl::attributes::floorwidth>, mbgl::InterpolationUniform<mbgl::attributes::gapwidth>, mbgl::InterpolationUniform<mbgl::attributes::offset>, mbgl::InterpolationUniform<mbgl::attributes::opacity>, mbgl::InterpolationUniform<mbgl::attributes::pattern_to>, mbgl::InterpolationUniform<mbgl::attributes::pattern_from>, mbgl::InterpolationUniform<mbgl::attributes::width>, mbgl::uniforms::blur, mbgl::uniforms::color, mbgl::uniforms::floorwidth, mbgl::uniforms::gapwidth, mbgl::uniforms::offset, mbgl::uniforms::opacity, mbgl::uniforms::pattern_to, mbgl::uniforms::pattern_from, mbgl::uniforms::width> > const&, mbgl::gfx::AttributeBindings<mbgl::TypeList<mbgl::attributes::pos_normal, mbgl::attributes::data<unsigned char, 4ul>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::blur>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::color>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::floorwidth>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::gapwidth>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::offset>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::opacity>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::pattern_to>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::pattern_from>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::width> > > const&, mbgl::gfx::TextureBindings<mbgl::TypeList<> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) + 288
7  Mapbox                         0x104046f80 mbgl::RenderLineLayer::render(mbgl::PaintParameters&) + 952
8  Mapbox                         0x104076b3c mbgl::Renderer::Impl::render(mbgl::RenderTree const&) + 1640
9  Mapbox                         0x104075374 mbgl::Renderer::render(std::__1::shared_ptr<mbgl::UpdateParameters> const&) + 64
10 Mapbox                         0x104291e70 -[MGLMapView renderSync] + 136
11 Mapbox                         0x104248948 -[MGLMapViewImplDelegate glkView:drawInRect:] + 40
12 GLKit                          0x1b0fc8410 -[GLKView _display:] + 212
13 Mapbox                         0x10429320c -[MGLMapView updateFromDisplayLink:] + 436
14 QuartzCore                     0x183832748 CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 664
15 QuartzCore                     0x183909244 display_timer_callback(__CFMachPort*, void*, long, void*) + 280
16 CoreFoundation                 0x180573ce4 __CFMachPortPerform + 176
17 CoreFoundation                 0x180598098 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 60
18 CoreFoundation                 0x180597440 __CFRunLoopDoSource1 + 596
19 CoreFoundation                 0x180591320 __CFRunLoopRun + 2360
20 CoreFoundation                 0x1805904bc CFRunLoopRunSpecific + 600
21 GraphicsServices               0x1970a2820 GSEventRunModal + 164
22 UIKitCore                      0x182f3d164 -[UIApplication _run] + 1072
23 UIKitCore                      0x182f42840 UIApplicationMain + 168
24 fellbase                       0x1029f70c4 main + 7 (main.m:7)
25 libdyld.dylib                  0x180257e40 start + 4

Then there are various *FileSource threads with traces that look like:

com.mapbox.mbgl.AssetFileSource
0  libsystem_kernel.dylib         0x1ac758dd0 mach_msg_trap + 8
1  libsystem_kernel.dylib         0x1ac758184 mach_msg + 76
2  CoreFoundation                 0x180596cf8 __CFRunLoopServiceMachPort + 380
3  CoreFoundation                 0x180590ea8 __CFRunLoopRun + 1216
4  CoreFoundation                 0x1805904bc CFRunLoopRunSpecific + 600
5  CoreFoundation                 0x180591590 CFRunLoopRun + 64
6  Mapbox                         0x103f45f58 mbgl::util::Thread<mbgl::AssetFileSource::Impl>::Thread<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&>(std::__1::function<void ()>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::'lambda'()::operator()() + 228
7  Mapbox                         0x103f45d98 void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, mbgl::util::Thread<mbgl::AssetFileSource::Impl>::Thread<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&>(std::__1::function<void ()>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::'lambda'()> >(void*) + 56
8  libsystem_pthread.dylib        0x1c8509ca8 _pthread_start + 320
9  libsystem_pthread.dylib        0x1c8512788 thread_start + 8

sortedArrayUsingComparator() in RCTImageLoader.mm seems to be involved.

Not sure if this helps. Is there a way to pry out more info on the Xcode side by modifying the Scheme? Sorry, I didn't have to do any in-depth debugging with react-native so far.

mzu commented 4 years ago

@mfazekas I managed to get the crash report directly from my device via Xcode (Window->Devices). You can find it here.

mfazekas commented 4 years ago

@mzu sounds like this is being fixed in RN:

https://github.com/facebook/react-native/commit/edb6fa79791beb804e450ca4a562a248abf730e5

mzu commented 4 years ago

@mfazekas that's good news. Thanks for looking into this!