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

Adding annotations immediately after map initialization crashes #1874

Conversation

tmpsantos
Copy link
Contributor

Adding an annotation in viewDidLoad crashes if it's too soon after map init. Work around is to place annotation code in viewDidAppear.

* thread #11: tid = 0x2f7cf8, 0x0000000109264e0f Mapbox GL`mbgl::MapContext::updateAnnotationTiles(this=0x00000001197749b0, ids=0x00007f8ad3f0a1b8) + 463 at map_context.cpp:157, name = 'Map', stop reason = EXC_BAD_ACCESS (code=1, address=0x98)
  * frame #0: 0x0000000109264e0f Mapbox GL`mbgl::MapContext::updateAnnotationTiles(this=0x00000001197749b0, ids=0x00007f8ad3f0a1b8) + 463 at map_context.cpp:157
    frame #1: 0x000000010923e34e Mapbox GL`auto auto mbgl::util::Thread<mbgl::MapContext>::bind<void (this=0x00007f8ad3f0a1a0, args=0x00007f8ad3f0a1b8)(std::__1::unordered_set<mbgl::TileID, mbgl::TileID::Hash, std::__1::equal_to<mbgl::TileID>, std::__1::allocator<mbgl::TileID> > const&)>(void (mbgl::MapContext::*)(std::__1::unordered_set<mbgl::TileID, mbgl::TileID::Hash, std::__1::equal_to<mbgl::TileID>, std::__1::allocator<mbgl::TileID> > const&))::'lambda'(void (mbgl::MapContext::*&&)(std::__1::unordered_set<mbgl::TileID, mbgl::TileID::Hash, std::__1::equal_to<mbgl::TileID>, std::__1::allocator<mbgl::TileID> > const&))::operator()<std::__1::unordered_set<mbgl::TileID, mbgl::TileID::Hash, std::__1::equal_to<mbgl::TileID>, std::__1::allocator<mbgl::TileID> > >('lambda'(void (mbgl::MapContext::*&&)(std::__1::unordered_set<mbgl::TileID, mbgl::TileID::Hash, std::__1::equal_to<mbgl::TileID>, std::__1::allocator<mbgl::TileID> > const&))) const + 142 at thread.hpp:72
    frame #2: 0x000000010923e29b Mapbox GL`void mbgl::util::RunLoop::Invoker<auto mbgl::util::Thread<mbgl::MapContext>::bind<void (mbgl::MapContext::*)(std::__1::unordered_set<mbgl::TileID, mbgl::TileID::Hash, std::__1::equal_to<mbgl::TileID>, std::__1::allocator<mbgl::TileID> > const&)>(void (mbgl::MapContext::*)(std::__1::unordered_set<mbgl::TileID, mbgl::TileID::Hash, std::__1::equal_to<mbgl::TileID>, std::__1::allocator<mbgl::TileID> > const&))::'lambda'(void (mbgl::MapContext::*&&)(std::__1::unordered_set<mbgl::TileID, mbgl::TileID::Hash, std::__1::equal_to<mbgl::TileID>, std::__1::allocator<mbgl::TileID> > const&)), std::__1::tuple<std::__1::unordered_set<mbgl::TileID, mbgl::TileID::Hash, std::__1::equal_to<mbgl::TileID>, std::__1::allocator<mbgl::TileID> > > >::invoke<0ul>(this=0x00007f8ad3f0a148, (null)=std::__1::index_sequence<0UL> at 0x000000011976be98) + 75 at run_loop.hpp:110
    frame #3: 0x000000010923e118 Mapbox GL`mbgl::util::RunLoop::Invoker<auto mbgl::util::Thread<mbgl::MapContext>::bind<void (mbgl::MapContext::*)(std::__1::unordered_set<mbgl::TileID, mbgl::TileID::Hash, std::__1::equal_to<mbgl::TileID>, std::__1::allocator<mbgl::TileID> > const&)>(void (mbgl::MapContext::*)(std::__1::unordered_set<mbgl::TileID, mbgl::TileID::Hash, std::__1::equal_to<mbgl::TileID>, std::__1::allocator<mbgl::TileID> > const&))::'lambda'(void (mbgl::MapContext::*&&)(std::__1::unordered_set<mbgl::TileID, mbgl::TileID::Hash, std::__1::equal_to<mbgl::TileID>, std::__1::allocator<mbgl::TileID> > const&)), std::__1::tuple<std::__1::unordered_set<mbgl::TileID, mbgl::TileID::Hash, std::__1::equal_to<mbgl::TileID>, std::__1::allocator<mbgl::TileID> > > >::operator(this=0x00007f8ad3f0a148)() + 184 at run_loop.hpp:90
    frame #4: 0x000000010950052b Mapbox GL`mbgl::util::RunLoop::process(this=0x0000000119774b00) + 683 at run_loop.cpp:27
    frame #5: 0x0000000109506571 Mapbox GL`std::__1::__function::__func<std::__1::__bind<void (mbgl::util::RunLoop::*)(), mbgl::util::RunLoop*>, std::__1::allocator<std::__1::__bind<void (mbgl::util::RunLoop::*)(), mbgl::util::RunLoop*> >, void ()>::operator()() [inlined] decltype(__f=0x0000000119774b88, __a0=0x0000000119774b98)).*fp(std::__1::forward<>(fp1))) std::__1::__invoke<void (mbgl::util::RunLoop::*&)(), mbgl::util::RunLoop*&, void>(void (mbgl::util::RunLoop::*&&&)(), mbgl::util::RunLoop*&&&) + 134 at __functional_base:380
    frame #6: 0x00000001095064eb Mapbox GL`std::__1::__function::__func<std::__1::__bind<void (mbgl::util::RunLoop::*)(), mbgl::util::RunLoop*>, std::__1::allocator<std::__1::__bind<void (mbgl::util::RunLoop::*)(), mbgl::util::RunLoop*> >, void ()>::operator()() [inlined] std::__1::__bind_return<void (mbgl::util::RunLoop::*)(), std::__1::tuple<mbgl::util::RunLoop*>, std::__1::tuple<>, _is_valid_bind_return<void (mbgl::util::RunLoop::*)(), std::__1::tuple<mbgl::util::RunLoop*>, std::__1::tuple<> >::value>::type std::__1::__apply_functor<void (__f=0x0000000119774b88, __bound_args=0x0000000119774b98, (null)=__tuple_indices<0> at 0x000000011976c1e0, __args=0x000000011976c220)(), std::__1::tuple<mbgl::util::RunLoop*>, 0ul, std::__1::tuple<> >(void (mbgl::util::RunLoop::*&)(), std::__1::tuple<mbgl::util::RunLoop*>&, std::__1::__tuple_indices<0ul>, std::__1::tuple<>&&) + 40 at functional:2023
    frame #7: 0x00000001095064c3 Mapbox GL`std::__1::__function::__func<std::__1::__bind<void (mbgl::util::RunLoop::*)(), mbgl::util::RunLoop*>, std::__1::allocator<std::__1::__bind<void (mbgl::util::RunLoop::*)(), mbgl::util::RunLoop*> >, void ()>::operator()() [inlined] std::__1::__bind_return<void (mbgl::util::RunLoop::*)(), std::__1::tuple<mbgl::util::RunLoop*>, std::__1::tuple<>, _is_valid_bind_return<void (mbgl::util::RunLoop::*)(), std::__1::tuple<mbgl::util::RunLoop*>, std::__1::tuple<> >::value>::type std::__1::__bind<void (this=0x0000000119774b88)(), mbgl::util::RunLoop*>::operator()<>() + 28 at functional:2086
    frame #8: 0x00000001095064a7 Mapbox GL`std::__1::__function::__func<std::__1::__bind<void (mbgl::util::RunLoop::*)(), mbgl::util::RunLoop*>, std::__1::allocator<std::__1::__bind<void (mbgl::util::RunLoop::*)(), mbgl::util::RunLoop*> >, void ()>::operator()() [inlined] decltype(__f=0x0000000119774b88)(), mbgl::util::RunLoop*>&>(fp)(std::__1::forward<>(fp0))) std::__1::__invoke<std::__1::__bind<void (mbgl::util::RunLoop::*)(), mbgl::util::RunLoop*>&>(std::__1::__bind<void (mbgl::util::RunLoop::*)(), mbgl::util::RunLoop*>&&&) + 11 at __functional_base:413
    frame #9: 0x000000010950649c Mapbox GL`std::__1::__function::__func<std::__1::__bind<void (mbgl::util::RunLoop::*)(), mbgl::util::RunLoop*>, std::__1::allocator<std::__1::__bind<void (mbgl::util::RunLoop::*)(), mbgl::util::RunLoop*> >, void ()>::operator(this=0x0000000119774b80)() + 60 at functional:1370
    frame #10: 0x0000000109281c0f Mapbox GL`std::__1::function<void ()>::operator(this=0x0000000119774b80)() const + 143 at functional:1756
    frame #11: 0x0000000109281b53 Mapbox GL`uv::async::async_cb(a=0x00007f8ad3d83cc0, (null)=0) + 51 at uv_detail.hpp:127
    frame #12: 0x00000001095cdbae Mapbox GL`uv__async_event(loop=0x00007f8ad3d836f0, w=0x00007f8ad3d83878, nevents=1) + 174 at async.c:80
    frame #13: 0x00000001095cdf98 Mapbox GL`uv__async_io(loop=0x00007f8ad3d836f0, w=0x00007f8ad3d83880, events=1) + 296 at async.c:156
    frame #14: 0x00000001095e99ae Mapbox GL`uv__io_poll(loop=0x00007f8ad3d836f0, timeout=-1) + 3310 at kqueue.c:233
    frame #15: 0x00000001095ce6a3 Mapbox GL`uv_run(loop=0x00007f8ad3d836f0, mode=UV_RUN_DEFAULT) + 195 at core.c:317
    frame #16: 0x00000001095cb228 Mapbox GL`uv::loop::run(this=0x00000001197749a8) + 40 at uv_detail.hpp:62
    frame #17: 0x000000010926016b Mapbox GL`void mbgl::util::Thread<mbgl::MapContext>::run<std::__1::tuple<mbgl::View&, mbgl::FileSource&, mbgl::MapData&>, 0ul, 1ul, 2ul>(this=0x00007f8ad3d82f90, context=ThreadContext at 0x0000000119774ca8, params=0x00007fff56ab45a0, (null)=std::__1::index_sequence<0UL, 1UL, 2UL> at 0x0000000119774950) + 331 at thread.hpp:125
    frame #18: 0x000000010925ffcb Mapbox GL`mbgl::util::Thread<mbgl::MapContext>::Thread<mbgl::View&, mbgl::FileSource&, mbgl::MapData&>(this=0x00007f8ad3d82fc0)::'lambda'()::operator()() const + 411 at thread.hpp:104
    frame #19: 0x000000010925fbd4 Mapbox GL`std::__1::__thread_proxy<std::__1::tuple<mbgl::util::Thread<mbgl::MapContext>::Thread<mbgl::View&, mbgl::FileSource&, mbgl::MapData&>(mbgl::util::ThreadContext const&, mbgl::View&&&, mbgl::FileSource&&&, mbgl::MapData&&&)::'lambda'()> >(void*, void*) [inlined] std::__1::__invoke<mbgl::util::Thread<mbgl::MapContext>::Thread<mbgl::View&, mbgl::FileSource&, mbgl::MapData&>(mbgl::util::ThreadContext const&, mbgl::View&&&, mbgl::FileSource&&&, mbgl::MapData&&&)::'lambda'()>(__f=0x00007f8ad3d82fc0)::'lambda'()>(fp)(std::__1::forward<>(fp0))), mbgl::util::Thread<mbgl::MapContext>::Thread<mbgl::View&, mbgl::FileSource&, mbgl::MapData&>(mbgl::util::ThreadContext const&, mbgl::View&&&, mbgl::FileSource&&&, mbgl::MapData&&&)::'lambda'()&&) + 15 at __functional_base:413
    frame #20: 0x000000010925fbc5 Mapbox GL`std::__1::__thread_proxy<std::__1::tuple<mbgl::util::Thread<mbgl::MapContext>::Thread<mbgl::View&, mbgl::FileSource&, mbgl::MapData&>(mbgl::util::ThreadContext const&, mbgl::View&&&, mbgl::FileSource&&&, mbgl::MapData&&&)::'lambda'()> >(void*, void*) [inlined] _ZNSt3__116__thread_executeIZN4mbgl4util6ThreadINS1_10MapContextEEC1IJRNS1_4ViewERNS1_10FileSourceERNS1_7MapDataEEEERKNS2_13ThreadContextEDpOT_EUlvE_JEJEEEvRNS_5tupleIJT_DpT0_EEENS_15__tuple_indicesIJXspT1_EEEE(__t=0x00007f8ad3d82fc0, (null)=__tuple_indices<> at 0x0000000119774e30) + 28 at thread:332
    frame #21: 0x000000010925fba9 Mapbox GL`std::__1::__thread_proxy<std::__1::tuple<mbgl::util::Thread<mbgl::MapContext>::Thread<mbgl::View&, mbgl::FileSource&, mbgl::MapData&>(mbgl::util::ThreadContext const&, mbgl::View&&&, mbgl::FileSource&&&, mbgl::MapData&&&)::'lambda'()> >(__vp=0x00007f8ad3d82fc0) + 361 at thread:342
    frame #22: 0x000000010cf0c268 libsystem_pthread.dylib`_pthread_body + 131
    frame #23: 0x000000010cf0c1e5 libsystem_pthread.dylib`_pthread_start + 176
    frame #24: 0x000000010cf0a41d libsystem_pthread.dylib`thread_start + 13

This crash can be replicated like so, in iOS:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds];
    self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    self.mapView.showsUserLocation = YES;
    self.mapView.delegate = self;
    [self.view addSubview:self.mapView];

    // Add a polygon, which will crash
    CLLocationCoordinate2D coordinates[] = {
        CLLocationCoordinate2DMake(45.522585, -122.685699),
        CLLocationCoordinate2DMake(45.534611, -122.708873),
        CLLocationCoordinate2DMake(45.530883, -122.678833),
        CLLocationCoordinate2DMake(45.547115, -122.667503),
        CLLocationCoordinate2DMake(45.530643, -122.660121),
        CLLocationCoordinate2DMake(45.533529, -122.636260),
        CLLocationCoordinate2DMake(45.521743, -122.659091),
        CLLocationCoordinate2DMake(45.510677, -122.648792),
        CLLocationCoordinate2DMake(45.515008, -122.664070),
        CLLocationCoordinate2DMake(45.502496, -122.669048),
        CLLocationCoordinate2DMake(45.515369, -122.678489),
        CLLocationCoordinate2DMake(45.506346, -122.702007),
        CLLocationCoordinate2DMake(45.522585, -122.685699),
    };
    NSUInteger numberOfCoordinates = sizeof(coordinates) / sizeof(CLLocationCoordinate2D);

    MGLPolygon *shape = [MGLPolygon polygonWithCoordinates:coordinates count:numberOfCoordinates];

    [self.mapView addAnnotation:shape];

    // Or point annotations will crash, too
    MGLPointAnnotation *pisa = [MGLPointAnnotation new];
    pisa.coordinate = CLLocationCoordinate2DMake(43.723056, 10.396417);
    pisa.title = @"Leaning Tower of Pisa";

    [self.mapView addAnnotation:pisa];
}

Workaround:

- (void)viewDidAppear:(BOOL)animated
{
    MGLPointAnnotation *pisa = [MGLPointAnnotation new];
    pisa.coordinate = CLLocationCoordinate2DMake(43.723056, 10.396417);
    pisa.title = @"Leaning Tower of Pisa";

    [self.mapView addAnnotation:pisa];
}

/cc @incanus @kkaefer @ansis @1ec5

@1ec5
Copy link
Contributor

1ec5 commented Jul 10, 2015

@friedbunny, can you try this on the release-0.5.0 branch, which doesn’t have #1821?

@1ec5 1ec5 added iOS Mapbox Maps SDK for iOS and removed bug labels Jul 10, 2015
@friedbunny
Copy link
Contributor Author

@1ec5 Sorry, this was MapboxGL 0.5.0 via CocoaPods. No difference in master.

@tmpsantos
Copy link
Contributor

I managed to reproduce this one on Linux and I have a fix. It is related to the fact that the Style is loaded/parsed asynchronously.

The Style object might have been created but the Source is not
yet available because the JSON file was not set. Can happen
specially when the style is loaded from the network.
It is going to be used by another test that needs to emulate
asynchronous requests.
@1ec5
Copy link
Contributor

1ec5 commented Jul 10, 2015

Awesome, and thanks for the test.

@tmpsantos tmpsantos merged commit 30416c5 into master Jul 10, 2015
@mourner mourner removed the ready label Jul 10, 2015
@tmpsantos tmpsantos deleted the 1874-adding_annotations_immediately_after_map_initialization_crashes branch July 10, 2015 18:42
@friedbunny friedbunny added this to the v0.6.0 milestone Jul 22, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
crash iOS Mapbox Maps SDK for iOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants