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

Crash on launch without access token — mbgl::Style::loadJSON() #1147

Closed
1ec5 opened this issue Mar 27, 2015 · 12 comments · Fixed by #1184
Closed

Crash on launch without access token — mbgl::Style::loadJSON() #1147

1ec5 opened this issue Mar 27, 2015 · 12 comments · Fixed by #1184
Assignees
Labels
crash iOS Mapbox Maps SDK for iOS
Milestone

Comments

@1ec5
Copy link
Contributor

1ec5 commented Mar 27, 2015

Every time I launch the iOS demo app in various older iOS simulators (e.g., iPhone 4s or iPad 2 with iOS 8.2), I get the following crash:

Map (13)
#0  0x038fe695 in __cxa_throw ()
#1  0x0027b784 in mbgl::Style::loadJSON(unsigned char const*) at /Users/mxn/hub/mapbox-gl-native-2/src/mbgl/style/style.cpp:75
#2  0x0012c9ab in mbgl::Map::loadStyleJSON(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) at /Users/mxn/hub/mapbox-gl-native-2/src/mbgl/map/map.cpp:807
#3  0x0012c581 in mbgl::Map::reloadStyle() at /Users/mxn/hub/mapbox-gl-native-2/src/mbgl/map/map.cpp:797
#4  0x00125be4 in mbgl::Map::prepare() at /Users/mxn/hub/mapbox-gl-native-2/src/mbgl/map/map.cpp:822
#5  0x00125535 in mbgl::Map::run() at /Users/mxn/hub/mapbox-gl-native-2/src/mbgl/map/map.cpp:279
#6  0x0013b366 in mbgl::Map::start(bool)::$_5::operator()() const at /Users/mxn/hub/mapbox-gl-native-2/src/mbgl/map/map.cpp:183
…

Map::data is completely empty at this point: no json and no base. Those values wouldn’t be filled in until -[MGLMapView initWithFrame::accessToken:styleJSON:] calls -setStyleJSON: later on.

@1ec5 1ec5 added iOS Mapbox Maps SDK for iOS crash labels Mar 27, 2015
@incanus
Copy link
Contributor

incanus commented Mar 27, 2015

Can't seem to find it now, but I had flagged an issue for @peter related to float values in the half-sized 1x sprite JSON. Looks very similar.

@incanus incanus added this to the iOS Beta 1 milestone Mar 27, 2015
@incanus
Copy link
Contributor

incanus commented Mar 27, 2015

P.S. Isn't 4s retina?

@1ec5
Copy link
Contributor Author

1ec5 commented Mar 27, 2015

Whoops, you’re right, forgot to edit that part.

@incanus
Copy link
Contributor

incanus commented Mar 27, 2015

@1ec5 1ec5 changed the title Crash on launch in non-Retina iOS simulators — mbgl::Style::loadJSON() Crash on launch in older iOS simulators — mbgl::Style::loadJSON() Mar 27, 2015
@1ec5
Copy link
Contributor Author

1ec5 commented Mar 27, 2015

I’m not sure that’s related. What I’m seeing here is that the style URL is never set by the time the Map thread tries to parse the JSON (due to the absence of a style URL).

@1ec5
Copy link
Contributor Author

1ec5 commented Mar 27, 2015

This is where StyleInfo is set on the iPhone 6 simulator:

#0  0x0000000105926320 in mbgl::MapData::setStyleInfo(mbgl::StyleInfo&&) at /Users/mxn/hub/mapbox-gl-native-2/src/mbgl/map/map_data.hpp:33
#1  0x0000000105909d9d in mbgl::Map::setStyleURL(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) at /Users/mxn/hub/mapbox-gl-native-2/src/mbgl/map/map.cpp:409
#2  0x0000000105b92db9 in -[MGLMapView setStyleURL:] at /Users/mxn/hub/mapbox-gl-native-2/platform/ios/MGLMapView.mm:177
#3  0x0000000105ba40b0 in -[MGLMapView useBundledStyleNamed:] at /Users/mxn/hub/mapbox-gl-native-2/platform/ios/MGLMapView.mm:1273
#4  0x0000000105b928a4 in -[MGLMapView setStyleJSON:] at /Users/mxn/hub/mapbox-gl-native-2/platform/ios/MGLMapView.mm:165
#5  0x0000000105b91f7e in -[MGLMapView initWithFrame:accessToken:styleJSON:] at /Users/mxn/hub/mapbox-gl-native-2/platform/ios/MGLMapView.mm:115
#6  0x0000000105b92344 in -[MGLMapView initWithFrame:accessToken:] at /Users/mxn/hub/mapbox-gl-native-2/platform/ios/MGLMapView.mm:137
#7  0x0000000105857c28 in -[MBXViewController viewDidLoad] at /Users/mxn/hub/mapbox-gl-native-2/ios/app/MBXViewController.mm:66

The iPhone 4s simulator never gets here before the Map thread tries to parse JSON out of the StyleInfo.

@1ec5
Copy link
Contributor Author

1ec5 commented Mar 27, 2015

Doesn’t reproduce if I put in my access token.

@1ec5
Copy link
Contributor Author

1ec5 commented Mar 27, 2015

I also get this crash now when I put an MGLMapView in a storyboard (#1070) and set its accessToken as a user-defined runtime attribute instead of setting it in code.

@incanus
Copy link
Contributor

incanus commented Mar 28, 2015

@kkaefer Want to take a peek?

@1ec5 1ec5 changed the title Crash on launch in older iOS simulators — mbgl::Style::loadJSON() Crash on launch without access token — mbgl::Style::loadJSON() Mar 30, 2015
1ec5 added a commit that referenced this issue Mar 30, 2015
mbgl::Map is now started on demand, once either the access token or a bundled style name is set. The access token and style name are exposed to clients as ordinary KVO-compliant properties. Actually, they’re not so ordinary because they’re inspectable!

Ref #1070, #1147
@1ec5 1ec5 self-assigned this Mar 31, 2015
@1ec5
Copy link
Contributor Author

1ec5 commented Mar 31, 2015

#1163 just compounds the fact that we have too many ways to populate MGLMapView with a style:

  • accessToken → default bundled style
  • styleJSON
  • Bundled style name
  • accessToken + styleURL (in two flavors)
  • and we’ll need a separate styleID for IB users to input Mapbox style IDs, since you can’t have a user-defined runtime attribute of type NSURL

Each of these ways complicates my approach of only starting the mbgl::Map when we have enough information to be guaranteed a style. I’m going to try to funnel the various methods into one place that’s responsible for starting the map.

@incanus
Copy link
Contributor

incanus commented Mar 31, 2015

We are getting rid of:

  • Passing style JSON
  • Naming a bundled style

And I think we should keep the IB interaction to just map ID for simplicity & not have to cover every use case.

@1ec5
Copy link
Contributor Author

1ec5 commented Mar 31, 2015

OK, since my refactoring mucks around with both APIs, I’m going to tackle removing them along the way.

1ec5 added a commit that referenced this issue Apr 3, 2015
`Map` should be able to deal with having no access token or JSON even while it’s running. Most of `Map` accounts for this situation, but `reloadStyle()` incorrectly assumes that one or the other is set. This change corrects the assumption in `reloadStyle()`.

Also expose the access token and style name to clients as ordinary KVO-compliant properties. Actually, they’re not so ordinary because they’re inspectable!

Ref #1070, #1147
@1ec5 1ec5 closed this as completed in #1184 Apr 3, 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 a pull request may close this issue.

2 participants