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 rendering the map — mbgl::FillBucket::drawElements, glrAGXRenderVertexArray #5731
Copy link
Copy link
Closed
Milestone
Description
Platform: iOS
Mapbox SDK version: 3.3.1
We see a high crash rate for this on fabric.
I can't reproduce this crash but it happens randomly when the app is in foreground and doing something with the map.
We use a custom style & draw a single polyline on the map
Crashed: com.apple.main-thread
0 libsystem_platform.dylib 0x181e5a2a0 _platform_memmove + 176
1 AGXGLDriver 0x193d93f6c glrAGXRenderVertexArray(GLDContextRec*, unsigned int, unsigned int, int, int, unsigned int, void const*, int, void const*)
2 AGXGLDriver 0x193d93f6c glrAGXRenderVertexArray(GLDContextRec*, unsigned int, unsigned int, int, int, unsigned int, void const*, int, void const*)
3 GLEngine 0x194b36ea4 glDrawElements_ACC_ES2Exec
4 Mapbox 0x1017739e4 mbgl::FillBucket::drawElements(mbgl::PlainShader&, mbgl::gl::ObjectStore&) + 284
5 Mapbox 0x10177dd7c mbgl::Painter::renderFill(mbgl::FillBucket&, mbgl::style::FillLayer const&, mbgl::UnwrappedTileID const&, std::__1::array<double, 16ul> const&) + 3852
6 Mapbox 0x10177abb0 void mbgl::Painter::renderPass<std::__1::reverse_iterator<std::__1::__wrap_iter<mbgl::RenderItem const*> > >(mbgl::RenderPass, std::__1::reverse_iterator<std::__1::__wrap_iter<mbgl::RenderItem const*> >, std::__1::reverse_iterator<std::__1::__wrap_iter<mbgl::RenderItem const*> >, int, signed char) + 688
7 Mapbox 0x10177a244 mbgl::Painter::render(mbgl::style::Style const&, mbgl::FrameData const&, mbgl::SpriteAtlas&) + 1424
8 Mapbox 0x1017682ac mbgl::Map::Impl::render() + 160
9 Mapbox 0x10176811c mbgl::Map::render() + 128
10 Mapbox 0x1016ec2a8 -[MGLMapView glkView:drawInRect:] + 48
11 GLKit 0x18a89136c -[GLKView _display:] + 332
12 Mapbox 0x1016eca44 -[MGLMapView updateFromDisplayLink] + 68
13 QuartzCore 0x184d38234 CA::Display::DisplayLinkItem::dispatch() + 40
14 QuartzCore 0x184d380e8 CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 424
15 IOKit 0x182475e54 IODispatchCalloutFromCFMessage + 372
16 CoreFoundation 0x18219d030 __CFMachPortPerform + 180
17 CoreFoundation 0x1821b57d4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 56
18 CoreFoundation 0x1821b4f0c __CFRunLoopDoSource1 + 436
19 CoreFoundation 0x1821b2c64 __CFRunLoopRun + 1800
20 CoreFoundation 0x1820dcc50 CFRunLoopRunSpecific + 384
21 GraphicsServices 0x1839c4088 GSEventRunModal + 180
22 UIKit 0x1873c6088 UIApplicationMain + 204
23 PACEApp 0x1001b9ba8 main (AppDelegate.swift:27)
24 libdispatch.dylib 0x181c7a8b8 (Missing)
Other Threads:
DefaultFileSource
0 libsystem_kernel.dylib 0x181d7cfd8 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x181d7ce54 mach_msg + 72
2 CoreFoundation 0x1821b4c60 __CFRunLoopServiceMachPort + 196
3 CoreFoundation 0x1821b2964 __CFRunLoopRun + 1032
4 CoreFoundation 0x1820dcc50 CFRunLoopRunSpecific + 384
5 CoreFoundation 0x18212a3a4 CFRunLoopRun + 112
6 Mapbox 0x10181b438 void mbgl::util::Thread<mbgl::DefaultFileSource::Impl>::run<std::__1::tuple<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long long&>, 0ul, 1ul>(std::__1::tuple<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long long&>&&, std::__1::integer_sequence<unsigned long, 0ul, 1ul>) + 156
7 Mapbox 0x10181b358 std::__1::__thread_proxy<std::__1::tuple<mbgl::util::Thread<mbgl::DefaultFileSource::Impl>::Thread<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long long&>(mbgl::util::ThreadContext const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&&&, unsigned long long&&&)::'lambda'()> >(void*, void*) + 136
8 libsystem_pthread.dylib 0x181e63b28 _pthread_body + 156
9 libsystem_pthread.dylib 0x181e63a8c _pthread_body + 154
10 libsystem_pthread.dylib 0x181e61028 thread_start + 4
AssetFileSource
0 libsystem_kernel.dylib 0x181d7cfd8 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x181d7ce54 mach_msg + 72
2 CoreFoundation 0x1821b4c60 __CFRunLoopServiceMachPort + 196
3 CoreFoundation 0x1821b2964 __CFRunLoopRun + 1032
4 CoreFoundation 0x1820dcc50 CFRunLoopRunSpecific + 384
5 CoreFoundation 0x18212a3a4 CFRunLoopRun + 112
6 Mapbox 0x101816150 void mbgl::util::Thread<mbgl::AssetFileSource::Impl>::run<std::__1::tuple<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&>, 0ul>(std::__1::tuple<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&>&&, std::__1::integer_sequence<unsigned long, 0ul>) + 104
7 Mapbox 0x1018160a4 std::__1::__thread_proxy<std::__1::tuple<mbgl::util::Thread<mbgl::AssetFileSource::Impl>::Thread<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&>(mbgl::util::ThreadContext const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&&&)::'lambda'()> >(void*, void*) + 136
8 libsystem_pthread.dylib 0x181e63b28 _pthread_body + 156
9 libsystem_pthread.dylib 0x181e63a8c _pthread_body + 154
10 libsystem_pthread.dylib 0x181e61028 thread_start + 4
And a lot of worker threads that all look the same
Worker
0 libsystem_kernel.dylib 0x181d7cfd8 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x181d7ce54 mach_msg + 72
2 CoreFoundation 0x1821b4c60 __CFRunLoopServiceMachPort + 196
3 CoreFoundation 0x1821b2964 __CFRunLoopRun + 1032
4 CoreFoundation 0x1820dcc50 CFRunLoopRunSpecific + 384
5 CoreFoundation 0x18212a3a4 CFRunLoopRun + 112
6 Mapbox 0x10180c924 void mbgl::util::Thread<mbgl::Worker::Impl>::run<std::__1::tuple<> >(std::__1::tuple<>&&, std::__1::integer_sequence<unsigned long>) + 88
7 Mapbox 0x10180c888 std::__1::__thread_proxy<std::__1::tuple<mbgl::util::Thread<mbgl::Worker::Impl>::Thread<>(mbgl::util::ThreadContext const&)::'lambda'()> >(void*, void*) + 136
8 libsystem_pthread.dylib 0x181e63b28 _pthread_body + 156
9 libsystem_pthread.dylib 0x181e63a8c _pthread_body + 154
10 libsystem_pthread.dylib 0x181e61028 thread_start + 4
Activity
1ec5 commentedon Jul 23, 2016
We’ve seen some reports of this exact crash as well, on iOS 9.2.1 on an iPhone 6, several minutes after launch. It looks vaguely similar to #1792.
From your crash logs, are you able to tell whether the application is in the foreground, background, or background mode?Never mind, you said foreground already.[-]Crash in AGXGLDriver[/-][+]Crash rendering the map — mbgl::FillBucket::drawElements, glrAGXRenderVertexArray[/+]1ec5 commentedon Jul 23, 2016
Also, does anything appear in the console around the time of the crash, as suggested in this Apple Developer Forums thread?
/cc @kkaefer @brunoabinader @jfirebaugh
1ec5 commentedon Jul 27, 2016
Based on other reports we’ve received, as well as some automated reports via an internal testing tool, this issue appears to be triggered or exacerbated by continuous animation of the viewport for long stretches of time. Does that describe your situation, @MikeKasperlik?
MikeKasperlik commentedon Jul 28, 2016
We animate the viewport, but not for a long time. Based on what the user does, it can happen that the viewport gets animated often, but that are separate animations. I checked the logs and in some cases we do had similar entries as described in the developer thread.
incanus commentedon Aug 22, 2016
@MikeKasperlik Any chance you can share a minimal piece of code that triggers (always or frequently) this problem? Going to start looking into this.
incanus commentedon Aug 22, 2016
Going to try to repro myself and investigate.
incanus commentedon Aug 22, 2016
Also @MikeKasperlik more info welcome on device and/or version. Haven't documented this on devices newer than iPhone 6 or iOS later than 9.2.1 yet.
1ec5 commentedon Aug 22, 2016
Actually, we’re seeing some reports internally of similar crashes on iOS 9.3.3 on iPhone 6 Plus.
MikeKasperlik commentedon Aug 23, 2016
@incanus I can't say whats triggering this unfortunately. I do can provide you some more information:
Device stats:
Operating system:
Device status:
What's strange about this is, that we received quite a lot crashes until August 18th. Since then not a single crash without updating our app - maybe something with the delivered tiles ?
20 remaining items
u10int commentedon Oct 7, 2016
This is by far one of the most frequent crashes we're also seeing within our app since upgrading to v3.3.x of the Mapbox iOS SDK, among many other OpenGL-related crashes. Others have provided similar stacktraces related to this same issue, but here's another from our app which is using v3.3.4 of the SDK:
Haven't really seen any of these crashes come in for iOS 10 yet as most are from iOS 9.0. Also, it doesn't appear as if it's memory-related as several crashes were reporting free RAM > 15%.
jfirebaugh commentedon Oct 12, 2016
A common thread in all the stack traces is that the crash occurs when rendering the opaque pass for a fill layer. (You can tell it's the opaque pass because
Painter::renderPassis specialized forreverse_iteratorin the stack trace.) And from a couple complete crash logs, it appears to be a SIGSEGV on 0x0.I saw a crash like this when working on #6468. It happened when I introduced a bug that resulted in calling
glDrawElementswhen the currently-bound VAO had no element buffer binding. This is equivalent to callingglDrawElementswith no element buffer bound, in which case it interprets the final argument (whose value is usually(void*)0) as a pointer to CPU memory and tries to read from it.As a test, I reintroduced the bug in #6468 and I get almost exactly the same stack trace as seen here. In particular, the top of the stack trace is
_platform_memmove + 176-- the same symbol and offset. So I'm somewhat confident this crash is caused by callingglDrawElementswith a VAO in which no element buffer is bound.How would this happen? A VAO will have an unbound element buffer if:
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, …)after binding the VAO. (This was what the bug in C++ bindings for OpenGL #6468 was.)glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)with the VAO bound.glDeleteBuffers(…)on the bound buffer, with the VAO bound.glDeleteBuffers(…)on the bound buffer, without the VAO bound. (This is supposedly ok per the spec but problematic in practice.)I think this list is exhaustive. @kkaefer @ansis Can you think of anything I'm missing?
I've combed through the code, and I can't see where any of these issues are present. In particular:
glBindBufferisBuffer::bind. Is it somehow possible thatBuffer::bufferwinds up containing agl::UniqueBuffervalue of0? That would happen ifglGenBuffersproduced0, or merely did not overwrite the0that we initialize to. However, this seems implausible; I can't find any indications thatglGenBufferscan really "fail".Another question that might be the key to unravelling this is: why do we only see crashes in fill layers, and not any other layer type? If it was really a bug with VAO state, I'd expect at least some crashes on other layer types, since our use of VAOs isn't specific to fill layers.
jfirebaugh commentedon Oct 12, 2016
Other hypotheses explored, none of which seem plausible:
VertexArrayObject::bindin question is sometimes called with 4 arguments (no element buffer) and sometimes 5. Doesn't seem to be the case.VertexArrayObjects are somehow improperly sharing a single VAO id. Implausible.glGenVertexArraysorglBindVertexArrayfail, producing VAO id 0 or an unbound VAO. In this situation, the first call toglDrawElementswould work:VertexArrayObject::bindwould bind the necessary buffers, and it would look toglDrawElementslike you're simply not using a VAO. But then the second timeglDrawElementswas called,VertexArrayObject::bound_shaderwould be non-zero soVertexArrayObject::bindwouldn't do anything.Perhaps if a build that calls
glGetErrorafter every GL API call were widely distributed (i.e. defineMBGL_CHECK_ERROReven in Release configuration), we would catch some invalid API use that precedes the crash.aish504 commentedon Oct 13, 2016
Hi Mapbox,
We got the same crash, caught in Crashlytics
Any immediate fix?
jfirebaugh commentedon Oct 19, 2016
As a data-gathering mechanism, 596f9c5 enables error checking for all GL calls. We're not going to apply it in mainline releases because there may be usage scenarios where it would have a performance impact, but we can make targeted test builds that include it and see if they reveal anything interesting.
/cc @frederoni
MarcosMunoz commentedon Oct 21, 2016
For us it is happening very often in different devices, we use a map with a custom style.
jfirebaugh commentedon Nov 9, 2016
I was finally able to reproduce the bug locally and determine the cause. The crash is triggered when an application which uses multiple map views encounters a low-memory situation. In such a situation,
Map::onLowMemory()is called for each map. This method in turn calls a function which deletes unused but not yet deleted OpenGL resources, including VAOs.However,
Map::onLowMemory()failed to ensure the activation of the GL context to which those resources belong. Thus, the resources would get deleted in whichever context happens to be current at the time, most likely a context belonging to one of the other maps, which may be actively using identically-numbered resources. When this context subsequently attempts to use those resources, an error occurs. The error that I observed wasglBindVertexArrayreturningGL_INVALID_OPERATION-- we didn't observe this in the wild, but 596f9c5 was on the right track and may have eventually helped. In the absence of that change, theglBindVertexArrayfailure would have gone unnoticed, and I can easily see ways in which a subsequent draw operation with an unbound element buffer could occur.The fix is simple: #6972. We'll need to cherry pick this to the iOS and Android release branches, and should also consider an iOS 3.3.6 release that includes it -- I'm not sure that 057b7b7 will end up helping much.
1ec5 commentedon Nov 9, 2016
Should we revert 057b7b7 for v3.3.6?
jfirebaugh commentedon Nov 9, 2016
Yep.
boundsj commentedon Nov 10, 2016
Published ios-v3.3.6
volonbolon commentedon Nov 14, 2016
Upgraded to 3.3.6 and still crashing
jfirebaugh commentedon Nov 14, 2016
@volonbolon That is a different crash signature, one that I don't believe we've seen before. Can you please open a separate issue?
volonbolon commentedon Nov 14, 2016
Sure