maplibre-native: iOS Crash: Simulator Crash (glDrawElements) on custom style when camera is moved

Hello.

I made a small demo app to verify the crash I have in my production app. I tested this app with the default style and it works successfully.

We have a custom style which is way heavier than the default style, due the feature of the app. As soon as we move the viewPort with something like:

mapView.setCenter(CLLocationCoordinate2D(latitude: 52.414812, longitude: 13.046378), zoomLevel: 16, animated: true)

MapLibre crashes (note it crashes even non-animated)

Thread 1: EXC_BAD_ACCESS (code=1, address=0x7faa2058fd90)

I would like to know if you could help us out. We are not able to make the style simpler, but we would like to understand if there is something we can change to avoid the OpenGL Renderer to explode on camera movements.

Some Notes:

  • Manual user interactions (Pans, Zoom) are not crashing the map but are extremely laggy and slow
  • Programmatical changes are instantly crashing the renderer

Let me know if you want to have the Demo App (it’s just a full screen map tbh)

StackTrace

Thread 1 Queue : com.apple.main-thread (serial)
#0	0x00007fff4020f189 in glvmRasterOpDepthStencilTest ()
#1	0x00007fff4025d195 in glvmInterpretFPTransformFour ()
#2	0x00007fff5bca3f8e in gldLLVMFPTransform ()
#3	0x00007fff5bcb80c4 in gldLLVMVecPolyRender ()
#4	0x00007fff5bca0540 in gldRenderFillPolygonPtr ()
#5	0x000000011d4d616e in 0x11d4d616e ()
#6	0x00007fff400fd6f7 in gleFlushAtomicFunc ()
#7	0x00007fff4014a10d in glDrawElements_IMM_ES2Exec ()
#8	0x0000000110f811fa in mbgl::gl::Context::draw(mbgl::gfx::DrawMode const&, unsigned long, unsigned long) ()
#9	0x0000000110fe4c54 in mbgl::gl::Program<mbgl::SymbolSDFTextProgram>::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::label_plane_matrix, mbgl::uniforms::coord_matrix, mbgl::uniforms::extrude_scale, mbgl::uniforms::texsize, mbgl::uniforms::fade_change, mbgl::uniforms::is_text, mbgl::uniforms::camera_to_center_distance, mbgl::uniforms::pitch, mbgl::uniforms::pitch_with_map, mbgl::uniforms::rotate_symbol, mbgl::uniforms::aspect_ratio, mbgl::uniforms::gamma_scale, mbgl::uniforms::device_pixel_ratio, mbgl::uniforms::is_halo, mbgl::uniforms::is_size_zoom_constant, mbgl::uniforms::is_size_feature_constant, mbgl::uniforms::size_t, mbgl::uniforms::size, mbgl::InterpolationUniform<mbgl::attributes::opacity>, mbgl::InterpolationUniform<mbgl::attributes::fill_color>, mbgl::InterpolationUniform<mbgl::attributes::halo_color>, mbgl::InterpolationUniform<mbgl::attributes::halo_width>, mbgl::InterpolationUniform<mbgl::attributes::halo_blur>, mbgl::uniforms::opacity, mbgl::uniforms::fill_color, mbgl::uniforms::halo_color, mbgl::uniforms::halo_width, mbgl::uniforms::halo_blur> > const&, mbgl::gfx::DrawScope&, mbgl::gfx::AttributeBindings<mbgl::TypeList<mbgl::attributes::pos_offset, mbgl::attributes::data<unsigned short, 4ul>, mbgl::attributes::pixeloffset, mbgl::attributes::projected_pos, mbgl::attributes::fade_opacity, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::opacity>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::fill_color>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::halo_color>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::halo_width>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::halo_blur> > > const&, mbgl::gfx::TextureBindings<mbgl::TypeList<mbgl::textures::texture> > const&, mbgl::gfx::IndexBuffer const&, unsigned long, unsigned long) ()
#10	0x0000000111059cf8 in void mbgl::SymbolProgram<mbgl::SymbolSDFTextProgram, (mbgl::gfx::PrimitiveType)2, mbgl::TypeList<mbgl::attributes::pos_offset, mbgl::attributes::data<unsigned short, 4ul>, mbgl::attributes::pixeloffset>, mbgl::TypeList<mbgl::uniforms::matrix, mbgl::uniforms::label_plane_matrix, mbgl::uniforms::coord_matrix, mbgl::uniforms::extrude_scale, mbgl::uniforms::texsize, mbgl::uniforms::fade_change, mbgl::uniforms::is_text, mbgl::uniforms::camera_to_center_distance, mbgl::uniforms::pitch, mbgl::uniforms::pitch_with_map, mbgl::uniforms::rotate_symbol, mbgl::uniforms::aspect_ratio, mbgl::uniforms::gamma_scale, mbgl::uniforms::device_pixel_ratio, mbgl::uniforms::is_halo>, mbgl::TypeList<mbgl::textures::texture>, mbgl::style::TextPaintProperties>::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&, mbgl::Segment<mbgl::TypeList<mbgl::attributes::pos_offset, mbgl::attributes::data<unsigned short, 4ul>, mbgl::attributes::pixeloffset, mbgl::attributes::projected_pos, mbgl::attributes::fade_opacity, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::opacity>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::fill_color>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::halo_color>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::halo_width>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::halo_blur> > > const&, mbgl::gfx::UniformValues<mbgl::TypeList<mbgl::uniforms::matrix, mbgl::uniforms::label_plane_matrix, mbgl::uniforms::coord_matrix, mbgl::uniforms::extrude_scale, mbgl::uniforms::texsize, mbgl::uniforms::fade_change, mbgl::uniforms::is_text, mbgl::uniforms::camera_to_center_distance, mbgl::uniforms::pitch, mbgl::uniforms::pitch_with_map, mbgl::uniforms::rotate_symbol, mbgl::uniforms::aspect_ratio, mbgl::uniforms::gamma_scale, mbgl::uniforms::device_pixel_ratio, mbgl::uniforms::is_halo, mbgl::uniforms::is_size_zoom_constant, mbgl::uniforms::is_size_feature_constant, mbgl::uniforms::size_t, mbgl::uniforms::size, mbgl::InterpolationUniform<mbgl::attributes::opacity>, mbgl::InterpolationUniform<mbgl::attributes::fill_color>, mbgl::InterpolationUniform<mbgl::attributes::halo_color>, mbgl::InterpolationUniform<mbgl::attributes::halo_width>, mbgl::InterpolationUniform<mbgl::attributes::halo_blur>, mbgl::uniforms::opacity, mbgl::uniforms::fill_color, mbgl::uniforms::halo_color, mbgl::uniforms::halo_width, mbgl::uniforms::halo_blur> > const&, mbgl::gfx::AttributeBindings<mbgl::TypeList<mbgl::attributes::pos_offset, mbgl::attributes::data<unsigned short, 4ul>, mbgl::attributes::pixeloffset, mbgl::attributes::projected_pos, mbgl::attributes::fade_opacity, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::opacity>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::fill_color>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::halo_color>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::halo_width>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::halo_blur> > > const&, mbgl::gfx::TextureBindings<mbgl::TypeList<mbgl::textures::texture> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) ()
#11	0x0000000111058a9f in auto void mbgl::(anonymous namespace)::drawText<mbgl::RenderSymbolLayer::render(mbgl::PaintParameters&)::$_1>(mbgl::RenderSymbolLayer::render(mbgl::PaintParameters&)::$_1 const&, mbgl::RenderTile const&, mbgl::LayerRenderData const&, mapbox::util::variant<std::__1::reference_wrapper<mbgl::Segment<mbgl::TypeList<mbgl::attributes::pos_offset, mbgl::attributes::data<unsigned short, 4ul>, mbgl::attributes::pixeloffset, mbgl::attributes::projected_pos, mbgl::attributes::fade_opacity, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::opacity>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::fill_color>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::halo_color>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::halo_width>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::halo_blur> > > >, std::__1::reference_wrapper<std::__1::vector<mbgl::Segment<mbgl::TypeList<mbgl::attributes::pos_offset, mbgl::attributes::data<unsigned short, 4ul>, mbgl::attributes::pixeloffset, mbgl::attributes::projected_pos, mbgl::attributes::fade_opacity, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::opacity>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::fill_color>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::halo_color>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::halo_width>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::halo_blur> > >, std::__1::allocator<mbgl::Segment<mbgl::TypeList<mbgl::attributes::pos_offset, mbgl::attributes::data<unsigned short, 4ul>, mbgl::attributes::pixeloffset, mbgl::attributes::projected_pos, mbgl::attributes::fade_opacity, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::opacity>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::fill_color>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::halo_color>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::halo_width>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::halo_blur> > > > > > >, mbgl::SymbolBucket::PaintProperties const&, mbgl::PaintParameters const&)::'lambda'(mbgl::RenderSymbolLayer::render(mbgl::PaintParameters&)::$_1&, auto const&, auto const&, mbgl::SymbolSDFPart)::operator()<mbgl::SymbolSDFTextProgram, mbgl::gfx::UniformValues<mbgl::TypeList<mbgl::uniforms::matrix, mbgl::uniforms::label_plane_matrix, mbgl::uniforms::coord_matrix, mbgl::uniforms::extrude_scale, mbgl::uniforms::texsize, mbgl::uniforms::fade_change, mbgl::uniforms::is_text, mbgl::uniforms::camera_to_center_distance, mbgl::uniforms::pitch, mbgl::uniforms::pitch_with_map, mbgl::uniforms::rotate_symbol, mbgl::uniforms::aspect_ratio, mbgl::uniforms::gamma_scale, mbgl::uniforms::device_pixel_ratio, mbgl::uniforms::is_halo> >, mbgl::gfx::TextureBindings<mbgl::TypeList<mbgl::textures::texture> > >(mbgl::RenderSymbolLayer::render(mbgl::PaintParameters&)::$_1&, auto const&, auto const&, mbgl::SymbolSDFPart) const ()
#12	0x0000000111050d46 in void mbgl::(anonymous namespace)::drawText<mbgl::RenderSymbolLayer::render(mbgl::PaintParameters&)::$_1>(mbgl::RenderSymbolLayer::render(mbgl::PaintParameters&)::$_1 const&, mbgl::RenderTile const&, mbgl::LayerRenderData const&, mapbox::util::variant<std::__1::reference_wrapper<mbgl::Segment<mbgl::TypeList<mbgl::attributes::pos_offset, mbgl::attributes::data<unsigned short, 4ul>, mbgl::attributes::pixeloffset, mbgl::attributes::projected_pos, mbgl::attributes::fade_opacity, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::opacity>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::fill_color>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::halo_color>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::halo_width>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::halo_blur> > > >, std::__1::reference_wrapper<std::__1::vector<mbgl::Segment<mbgl::TypeList<mbgl::attributes::pos_offset, mbgl::attributes::data<unsigned short, 4ul>, mbgl::attributes::pixeloffset, mbgl::attributes::projected_pos, mbgl::attributes::fade_opacity, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::opacity>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::fill_color>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::halo_color>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::halo_width>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::halo_blur> > >, std::__1::allocator<mbgl::Segment<mbgl::TypeList<mbgl::attributes::pos_offset, mbgl::attributes::data<unsigned short, 4ul>, mbgl::attributes::pixeloffset, mbgl::attributes::projected_pos, mbgl::attributes::fade_opacity, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::opacity>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::fill_color>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::halo_color>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::halo_width>, mbgl::ZoomInterpolatedAttribute<mbgl::attributes::halo_blur> > > > > > >, mbgl::SymbolBucket::PaintProperties const&, mbgl::PaintParameters const&) ()
#13	0x000000011104f6f7 in mbgl::RenderSymbolLayer::render(mbgl::PaintParameters&) ()
#14	0x000000011107593f in mbgl::Renderer::Impl::render(mbgl::RenderTree const&) ()
#15	0x0000000111073ef3 in mbgl::Renderer::render(std::__1::shared_ptr<mbgl::UpdateParameters> const&) ()
#16	0x0000000111308081 in MGLRenderFrontend::render() [inlined] at /Users/runner/work/maplibre-gl-native/maplibre-gl-native/platform/ios/platform/darwin/src/MGLRendererFrontend.h:57
#17	0x000000011130803d in -[MGLMapView renderSync] at /Users/runner/work/maplibre-gl-native/maplibre-gl-native/platform/ios/platform/ios/src/MGLMapView.mm:1024
#18	0x00000001112bf690 in MGLMapViewImpl::render() [inlined] at /Users/runner/work/maplibre-gl-native/maplibre-gl-native/platform/ios/platform/ios/src/MGLMapView+Impl.mm:14
#19	0x00000001112bf671 in -[MGLMapViewImplDelegate glkView:drawInRect:] at /Users/runner/work/maplibre-gl-native/maplibre-gl-native/platform/ios/platform/ios/src/MGLMapView+OpenGL.mm:26
#20	0x00007fff4ef6a3f4 in -[GLKView _display:] ()
#21	0x00007fff28a71721 in CA::Layer::layout_and_display_if_needed(CA::Transaction*) ()
#22	0x00007fff289937c9 in CA::Context::commit_transaction(CA::Transaction*, double, double*) ()
#23	0x00007fff289cae86 in CA::Transaction::commit() ()
#24	0x00007fff289cc104 in CA::Transaction::flush_as_runloop_observer(bool) ()
#25	0x00007fff2037267d in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ ()
#26	0x00007fff2036ce41 in __CFRunLoopDoObservers ()
#27	0x00007fff2036d3d9 in __CFRunLoopRun ()
#28	0x00007fff2036ca90 in CFRunLoopRunSpecific ()
#29	0x00007fff2cb72c8e in GSEventRunModal ()
#30	0x00007fff2508e90e in -[UIApplication _run] ()
#31	0x00007fff25093569 in UIApplicationMain ()
#32	0x00007fff59ab0cc2 in UIApplicationMain(_:_:_:_:) ()
#33	0x000000010f3a19a8 in static UIApplicationDelegate.main() ()
#34	0x000000010f3a1937 in static AppDelegate.$main() at Demo/AppDelegate.swift:10
#35	0x000000010f3a1a28 in main ()
#36	0x000000010f61af21 in start_sim ()
#37	0x000000011cc0751e in start ()

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 5
  • Comments: 31 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks for the summary @racer1988. I think that MapLibre GL Native will see substantial changes in the near future. Tonight we have an Advisory Council meeting with our sponsors and I will publish some meeting notes tomorrow probably. One big discussion topic will be how to move forward with Native…

@wipfli Thank you for the info! Looking forward to the Meeting Notes. Would you kindly also link them here tomorrow? Thanks!

@atierian Sorry for missing those details:

  • Issue is simulator only. I suspect it’s due to OpenGL rendering in Simulators
  • It’s happening on both Intel and M1 Chips.
  • It is happening always on 15.4 simulators.
  • It’s happening also with default MapLibre style.
  • It’s happening way faster when using a heavier custom style

To our tests this is mostly due to 15.4 environment. I will report if I can see issues on other simulator versions

We are dropping OpenGL support on iOS in favor of Metal.

Please try out the new pre-release and create a new issue if you run into any problems.

Advisory Council meeting notes are here: https://github.com/maplibre/maplibre/discussions/104

Guys, at this point, if you want to experiment, you can try this bundle of binaries:

https://sygic-travel-dist.s3.amazonaws.com/ios/libs/Mapbox-5.9.0.zip

(which has some extras for our commercial project like support for @3x resources) or build your own ones for testing from my forked repository, metal-support-new branch.

I’ll try to update the proposed Pull request here in Maplibre so that is more usable for possible integration. 👍

@roblabs Thank you for the detailed explanation!

Unfortunately for our use case we are unable to disable arm64 architecture (we did in the past) due to side effects in other libraries.

From your analysis, iOS 16 Beta seems like a promising solution to avoid the exception (EXC_BAD_ACCESS) and work on simulators with all architecture (despite the warning).

I am looking forward to the Meeting Notes for the future of MapLibre.

@racer1988 — Thank you for the original issue report back in April 2022. Your issue & logs was helpful in running down this problem around Apple Silicon and the iOS 15 SDK.

Please see the discussion and my observations on the pass/failure table at https://github.com/maplibre/maplibre-gl-native-distribution/issues/7. In my opinion, there is no short term workaround that comes from the MapLibre source. Each app developer using Apple Silicon, whether building from source or consuming the binary from a Swift Package needs to make a change detailed at https://github.com/maplibre/maplibre-gl-native-distribution/issues/7.

I’ve updated your points (in italics) with my observations & comments from that link.

@racer1988: As the reporter of the issue, I would like to ask what is the plan of the community for this topic.

These are the recollection of points from discussions in various thread and my assumptions:

  • App using MapLibre on Simulators are crashing on all iOS Versions and Xcode Version.

Simulators running iOS 14 & 16 do not have an exception. iOS 15 does.

  • x86 Architecture has a easier time since it “probably” supports easily OpenGL.

This is good observation and possibly true. Targeting x86_64 in your app regardless of using Apple Silicon or Intel Macs seems to be right workaround for MapLibre running Open GL. The MapLibre Swift Package provides both arm64 & x86_64 binaries, so it’s up to the app developer using MapLibre to configure a proper workaround.

  • Arm Architecture (M1 etc) crashes immediately (probably lacks some OpenGL support).

Only on iOS Simulators targeting arm64 and iOS 15 SDK and Apple Silicon Mac.

  • Rosetta seems to alleviate the issue, because it probably helps with OpenGL support on ARM.

Rosetta is not a recommended workaround

I don’t want to panic prematurely 😓, but with Xcode 14 & iOS 16 Simulator, I’m getting an instant crash on launch, probably referencing something not going well in OS-level frameworks related to GL support.

Running the framework works okay on a physical device (no red alert escalation needed), no matter when run on iOS 16 device from Xcode 13 or 14. But the Simulator issues & development will probably become more serious. 🔥

@wipfli I could help with what I’m capable of, yet I’m not really an OpenGL/Metal guy, so any ideas in these areas are a bit of a black magic unfortunately. I’ll at least try to experiment with the MetalANGLE path at this moment. 🤞

Update

The Metal branch (at least a bit older checkout with some customisations for a project where I used Mapbox) works pretty fine in the iOS 15.5 & 16 Simulators (not even mentioning the HW acceleration, that’s huuge); the crashes I experience with the regular framework do not appear there, so far so good. 👌 Seems like pushing forward the MetalANGLE branch could be a topic for this summer holiday. 👀