mapbox / mapbox-maps-ios

Interactive, thoroughly customizable maps for iOS powered by vector tiles and Metal
https://www.mapbox.com/mapbox-mobile-sdk
Other
479 stars 156 forks source link

Stack Overflow in ModelLayer #2075

Open MichaelDanielTom opened 10 months ago

MichaelDanielTom commented 10 months ago

Environment

Observed behavior and steps to reproduce

Frequent updates to a ModelLayer's style (using a geojson feature collection of points as a source) eventually cause a stack overflow crash if there are lots of other frequently updating layers and modelScale is set to a zoom interpolated expression. Separately, I think this might have something to do with the duration of animations for modelRotation not calculating properly (If I set model rotation transition to duration=100 seconds the animation takes ~4 seconds to complete, and if the duration less the crash happens less).

In particular, I was able to get it to reliably crash by simultaneously:

1) Rotating by 180 degrees every second (setting the ModelLayer's modelRotation from [0, 0, 0] to [0, 0, 180]) 2) Having modelRotationTransition set to duration 100 seconds. 3) Having modelScale set to interpolate based on zoom. Importantly, I was not able to get it to crash if modelScale is just a regular vector like [1, 1, 1]. Example complex modelScale:

modelScale = ['interpolate', ['linear'], ['zoom'],
  11,
  [['*', 10, 40], ['*', 10, 40], ['*', 10, 40]],
  15,
  [['*', 5, 40], ['*', 5, 40], ['*', 5, 40]],
];

4) Wait 10 seconds to 2 minutes. The more other stuff is moving around (e.g. having a lot of symbols in a SymbolLayer animating by changing the source geojson's coordinates multiple times/second), the quicker the crash seems to happen. However it hasn't been deterministic as to how long it takes.

The models always initially loads and work as expected for a while, with the rotation animating, interpolated scale based on zoom working, and everything rendering correctly. And thanks all the 3d stuff team, it's really awesome :)

Here's the trace:

EXC_BAD_ACCESS: Stack overflow in (null)

0  MapboxCoreMaps +0x301634 mbgl::RenderModelLayer::evaluate(mbgl::PropertyEvaluationParameters const&)
1  MapboxCoreMaps +0x34f688 mbgl::RenderOrchestrator::createRenderTree(std::__1::shared_ptr<mbgl::UpdateParameters> const&, mbgl::ShadowRenderer*)
2  MapboxCoreMaps +0x36d58c mbgl::Renderer::render(std::__1::shared_ptr<mbgl::UpdateParameters> const&)
3  MapboxCoreMaps +0xaad68  mapbox::maps::MapImpl::Impl::render()
4  MapboxCoreMaps +0xa6c2c  -[MBMMetalViewDelegate drawInMTKView:]
5  MetalKit +0x204c         -[MTKView draw]
6  MapboxMaps +0x10838c     MapView.updateFromDisplayLink(displayLink:) (MapView.swift:605:24)
7  MapboxMaps +0x108b08     closure #1 in MapView.didMoveToWindow() (MapView.swift:640:23)
8  MapboxMaps +0xaa568      ForwardingDisplayLinkTarget.update(with:) (ForwardingDispalyLinkTarget.swift:11:9)
9  QuartzCore +0x29324      CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long)
10 QuartzCore +0x146e64     CA::Display::DisplayLink::dispatch_deferred_display_links(unsigned int)
11 UIKitCore +0x64dd90      __UIUpdateSequenceRun
12 UIKitCore +0xcb2890      _schedulerStepScheduledMainSection
13 UIKitCore +0xcb1dec      _runloopSourceCallback
14 CoreFoundation +0xd3124  ___CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
15 CoreFoundation +0xdf7b0  ___CFRunLoopDoSource0
16 CoreFoundation +0x645e4  ___CFRunLoopDoSources0
17 CoreFoundation +0x7a0d0  ___CFRunLoopRun
18 CoreFoundation +0x7f3e8  _CFRunLoopRunSpecific
19 GraphicsServices +0x1358 _GSEventRunModal
20 UIKitCore +0x39cf54      -[UIApplication _run]
21 UIKitCore +0x39cbb8      _UIApplicationMain
22 RadiateDev +0xe7f0       0x10000e7f0 (0x10000e778 + 120)
23 dyld +0x15de8            start
sunhongjihaha commented 10 months ago

I got so many crash like this trace 截屏2023-12-08 16 57 07

OdNairy commented 10 months ago

May you share a full crash log file?

MichaelDanielTom commented 10 months ago

Update: I'm pretty sure it was related to the super long transition duration (>100000) that was set for modelRotationTransition - since lowering it in our app to something less than 10000, I have not been able to make it crash again.