Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Crashes in MGLMapView.mm line 961 [MGLMapView glkView:drawInRect:] #11910

Closed
cirlam opened this issue May 15, 2018 · 8 comments
Closed

Crashes in MGLMapView.mm line 961 [MGLMapView glkView:drawInRect:] #11910

cirlam opened this issue May 15, 2018 · 8 comments
Labels
Core The cross-platform C++ core, aka mbgl crash iOS Mapbox Maps SDK for iOS needs information

Comments

@cirlam
Copy link

cirlam commented May 15, 2018

Hi,

Had a couple of my users experience the following issue on iPhone 6, iOS 11.3.1. I'm not sure what exactly is happening on the app at time of crash, but maybe the stack trace makes more sense to you?

Edit: iOS MapBox SDK 3.7.7

Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x4146749328d00000

0  Mapbox                         0x1009df96c mapbox::util::variant<mbgl::style::Undefined, mbgl::style::LightAnchorType, mbgl::style::CameraFunction<mbgl::style::LightAnchorType> >::variant(mapbox::util::variant<mbgl::style::Undefined, mbgl::style::LightAnchorType, mbgl::style::CameraFunction<mbgl::style::LightAnchorType> > const&) (variant.hpp:593)
1  Mapbox                         0x100b66348 mbgl::style::Transitionable<mbgl::style::PropertyValue<mbgl::style::LightAnchorType> >::transition(mbgl::TransitionParameters const&, mbgl::style::Transitioning<mbgl::style::PropertyValue<mbgl::style::LightAnchorType> >) const + 766920
2  Mapbox                         0x100b6566c mbgl::style::Properties<mbgl::style::LightAnchor, mbgl::style::LightPosition, mbgl::style::LightColor, mbgl::style::LightIntensity>::Transitionable::transitioned(mbgl::TransitionParameters const&, mbgl::style::Properties<mbgl::style::LightAnchor, mbgl::style::LightPosition, mbgl::style::LightColor, mbgl::style::LightIntensity>::Unevaluated&&) const + 763628
3  Mapbox                         0x100b6559c mbgl::RenderLight::transition(mbgl::TransitionParameters const&) + 763420
4  Mapbox                         0x100b6d740 mbgl::Renderer::Impl::render(mbgl::UpdateParameters const&) + 796608
5  Mapbox                         0x100a342f8 MGLRenderFrontend::render() (MGLRendererFrontend.h:53)
6  Mapbox                         0x100a3429c -[MGLMapView glkView:drawInRect:] (MGLMapView.mm:961)
7  GLKit                          0x190d82970 -[GLKView _display:] + 216
8  Mapbox                         0x100a34aa4 -[MGLMapView updateFromDisplayLink] (MGLMapView.mm:1092)
9  QuartzCore                     0x1877da3c0 CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 832
10 IOKit                          0x1839e38a0 IODispatchCalloutFromCFMessage + 492
11 CoreFoundation                 0x183708b20 __CFMachPortPerform + 188
12 CoreFoundation                 0x183723ae8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 56
13 CoreFoundation                 0x183723230 __CFRunLoopDoSource1 + 440
14 CoreFoundation                 0x183720c80 __CFRunLoopRun + 2456
15 CoreFoundation                 0x183640da8 CFRunLoopRunSpecific + 552
16 GraphicsServices               0x185623020 GSEventRunModal + 100
17 UIKit                          0x18d62178c UIApplicationMain + 236
18 ShredMate                      0x1006dc984 main (BluetoothUUIDs.swift:14)
19 libdyld.dylib                  0x1830d1fc0 start + 4
@friedbunny friedbunny added iOS Mapbox Maps SDK for iOS crash Core The cross-platform C++ core, aka mbgl labels May 15, 2018
@friedbunny
Copy link
Contributor

@cirlam Thanks for the report — please add the Mapbox SDK version that you’re using to the original post. 🙇

Any ideas, @ivovandongen?

@cirlam
Copy link
Author

cirlam commented May 15, 2018

Sure - all updated. (iOS Mapbox SDK 3.7.7)

@cirlam
Copy link
Author

cirlam commented May 16, 2018

I've had another crash permeating from the same MGLMapView.mm line 961, but resulting in a slightly different stack trace. I'm assuming they're the same issue - perhaps it helps to see both. Same MapBox iOS SDK as above, this one failed on an iPhone 8.1 Plus, iOS 11.3.1.

Also worth noting that on all the crashes seen, there is less than 100mb free ram available (ranges from 64mb to 88mb).

Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x42746e6f72467385

Crashed: com.apple.main-thread
0  Mapbox                         0x1030e8934 mbgl::style::IntervalStops<mbgl::Color>::evaluate(float) const + 432564
1  Mapbox                         0x103107124 mapbox::util::detail::dispatcher<mapbox::util::visitor<mbgl::style::CameraFunction<mbgl::Color>::evaluate(float) const::'lambda'(mbgl::Color const&)>, mapbox::util::variant<mbgl::style::ExponentialStops<mbgl::Color>, mbgl::style::IntervalStops<mbgl::Color> >, mbgl::Color, mbgl::style::ExponentialStops<mbgl::Color>, mbgl::style::IntervalStops<mbgl::Color> >::apply_const(mapbox::util::variant<mbgl::style::ExponentialStops<mbgl::Color>, mbgl::style::IntervalStops<mbgl::Color> > const&, mapbox::util::visitor<mbgl::style::CameraFunction<mbgl::Color>::evaluate(float) const::'lambda'(mbgl::Color const&)>&&) + 557476
2  Mapbox                         0x1031070d4 mapbox::util::detail::dispatcher<mbgl::PropertyEvaluator<mbgl::Color> const&, mapbox::util::variant<mbgl::style::Undefined, mbgl::Color, mbgl::style::CameraFunction<mbgl::Color> >, mbgl::Color, mbgl::Color, mbgl::style::CameraFunction<mbgl::Color> >::apply_const(mapbox::util::variant<mbgl::style::Undefined, mbgl::Color, mbgl::style::CameraFunction<mbgl::Color> > const&, mbgl::PropertyEvaluator<mbgl::Color> const&) + 557396
3  Mapbox                         0x103107088 mapbox::util::detail::dispatcher<mbgl::PropertyEvaluator<mbgl::Color> const&, mapbox::util::variant<mbgl::style::Undefined, mbgl::Color, mbgl::style::CameraFunction<mbgl::Color> >, mbgl::Color, mbgl::style::Undefined, mbgl::Color, mbgl::style::CameraFunction<mbgl::Color> >::apply_const(mapbox::util::variant<mbgl::style::Undefined, mbgl::Color, mbgl::style::CameraFunction<mbgl::Color> > const&, mbgl::PropertyEvaluator<mbgl::Color> const&) + 557320
4  Mapbox                         0x103106f50 auto mbgl::style::Transitioning<mbgl::style::PropertyValue<mbgl::Color> >::evaluate<mbgl::PropertyEvaluator<mbgl::Color> >(mbgl::PropertyEvaluator<mbgl::Color> const&, std::__1::chrono::time_point<std::__1::chrono::time_point::steady_clock, std::__1::chrono::time_point::duration<long long, std::__1::chrono::ratio<1l, 1000000000l> > >) const + 557008
5  Mapbox                         0x103139b50 mbgl::style::Properties<mbgl::style::LightAnchor, mbgl::style::LightPosition, mbgl::style::LightColor, mbgl::style::LightIntensity>::Unevaluated::evaluate(mbgl::PropertyEvaluationParameters const&) const + 764880
6  Mapbox                         0x103139a68 mbgl::RenderLight::evaluate(mbgl::PropertyEvaluationParameters const&) + 764648
7  Mapbox                         0x103141760 mbgl::Renderer::Impl::render(mbgl::UpdateParameters const&) + 796640
8  Mapbox                         0x1030082f8 MGLRenderFrontend::render() (MGLRendererFrontend.h:53)
9  Mapbox                         0x10300829c -[MGLMapView glkView:drawInRect:] (MGLMapView.mm:961)
10 GLKit                          0x1925ea970 -[GLKView _display:] + 216
11 Mapbox                         0x103008aa4 -[MGLMapView updateFromDisplayLink] (MGLMapView.mm:1092)
12 QuartzCore                     0x1890423c0 CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 832
13 QuartzCore                     0x1890f76fc display_timer_callback(__CFMachPort*, void*, long, void*) + 240
14 CoreFoundation                 0x184f70b20 __CFMachPortPerform + 188
15 CoreFoundation                 0x184f8bae8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 56
16 CoreFoundation                 0x184f8b230 __CFRunLoopDoSource1 + 440
17 CoreFoundation                 0x184f88c80 __CFRunLoopRun + 2456
18 CoreFoundation                 0x184ea8da8 CFRunLoopRunSpecific + 552
19 GraphicsServices               0x186e8b020 GSEventRunModal + 100
20 UIKit                          0x18ee8978c UIApplicationMain + 236
21 ShredMate                      0x102d7c984 main (BluetoothUUIDs.swift:14)
22 libdyld.dylib                  0x184939fc0 start + 4

@jfirebaugh
Copy link
Contributor

@cirlam Are you able to reproduce this crash yourself? If there's a known way to reproduce the issue, it's likely we can fix it, but if the stack trace is all the information we have to go on, it's much less likely.

@cirlam
Copy link
Author

cirlam commented May 21, 2018

Hi, not yet - although I must admit I haven't tried too hard yet. I believe (from Crashlytics Logs I built in last week) that this problem occurs when the app is brought to the foreground after being in the background recording a cycle ride for some time.

I did have a idea today (not yet tested - will try it this evening), that perhaps I am referencing my mapView wrong:
@IBOutlet weak var mapView: MGLMapView!

My guess is that my weak reference is allowing the mapView object to get deallocated under memory pressure. From looking at the mapbox sample apps, it looks like the correct way to reference the map is like this: @IBOutlet var mapView: MGLMapView!

Do you think this could be the issue?

@cirlam
Copy link
Author

cirlam commented May 23, 2018

I have fixed my weak reference, but that has not solved the issue.

I have been able to recreate the problem - to visually show the speed of the bike rider on the route they take, I use lots of polylines to simulate a gradient polyline. I am carefully watching this. When it's implemented on iOS and Android I'll be updating to use the proper gradient SDK - but for the time being I'm using a new polyline every time the speed changes by a certain value.

When creating approx 4200 polylines (1 every second for 70 minutes), it crashes with EXC_BAD_ACCESS. At this point, the memory usage of the app isn't crazy at about 160mb - and the app's "didReceiveMemoryWarning" is not being fired.
I have tested the app running without the gradient polylines (i.e 1 polyline of a single colour for the route), and this lasted over 6 hours before I stopped the test.

I intend to run some more tests this evening, with Zombie objects turned on etc - but is there a limit on the number of polylines the iOS SDK can handle? My android app hasn't suffered from this problem.

I have updated my app to use Mapbox iOS SDK 4.0.1 and this test was on an iPhone 6, running iOS 11.3.1

@cirlam
Copy link
Author

cirlam commented May 25, 2018

Found the problem - I was updating the parameters of a Polyline object from a background thread. After updating the parameters of the Polyline object (still on the background thread), I created a copy of this Polyline object, ready to then display on the map view after I transitioned back to the main thread.
I didn't realise Swift by default creates a shallow copy, so when updating the parameters of the Polyline in the background thread, I was modifying the very same Polyline that the main thread is displaying - I have effectively been updating my map view from a background thread.

Fixed by using my own class within the background thread like this. The class doesn't have any link to the map view, and implements NSCopying, to give the option of performing a deep copy.

class RawPolyline : NSCopying {
    var color:UIColor?
    var coordinates:[CLLocationCoordinate2D]?
    
    func copy(with zone: NSZone? = nil) -> Any {
        let copy = RawPolyline()
        copy.color = self.color?.copy() as? UIColor
        copy.coordinates = self.coordinates
        return copy
    }
}

Once I transition to the main thread, I now populate the map with poly lines like this:

mCurrentPolyLine = CustomPolyline(coordinates: rawPolyline.coordinates, count: UInt(rawPolyline.coordinates.count))
                        mCurrentPolyLine?.color = rawPolyline.color
                          mapView?.addAnnotation(mCurrentPolyLine!)

(CustomPolyline is a subclass of MGLPolyline, with a color property)

@jfirebaugh
Copy link
Contributor

Great, glad you were able to find the issue!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Core The cross-platform C++ core, aka mbgl crash iOS Mapbox Maps SDK for iOS needs information
Projects
None yet
Development

No branches or pull requests

3 participants