Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash under iOS 12 in mapView.mapboxMap.style.localizeLabels() #954

Closed
aclauss opened this issue Dec 15, 2021 · 3 comments · Fixed by #1278
Closed

Crash under iOS 12 in mapView.mapboxMap.style.localizeLabels() #954

aclauss opened this issue Dec 15, 2021 · 3 comments · Fixed by #1278
Assignees
Labels
bug 🪲 Something is broken!

Comments

@aclauss
Copy link

aclauss commented Dec 15, 2021

Environment

  • Xcode version: 13.2
  • iOS version: iOS 12.45.5
  • Devices affected: iPhone, probably iPad
  • Maps SDK Version: V10

Observed behavior and steps to reproduce

After the map style has loaded I call the localize method to get localized map labels (I’ve loaded the „outdoor“ map style):
self.mapView.mapboxMap.style.localizeLabels(into: Locale.current)

This works fine under iOS 15 (probably also other iOS releases) but crashes under iOS 12 on my iPhone 5s (where I checked my App how it works on the tiny screen).

Fatal error: 'try!' expression unexpectedly raised an error: Swift.EncodingError.invalidValue(nil, Swift.EncodingError.Context(codingPath: [], debugDescription: "Top-level Optional<Value> encoded as null JSON fragment.", underlyingError: nil)): file MapboxMaps/Style+Localization.swift, line 28

Expected behavior

The Map applies the localization if available, if not available it uses the default (as documented).

Notes / preliminary analysis

According to the debugger output, the crash occurs in "Style+Localization.swift“ at line 28 because of the „try!“ which can not be catched for the call "convertExpressionForLocalization()“. Further analysis reveals that within "convertExpressionForLocalization()" in line 86 the „symbolLayer.textField“ is nil under iOS 12 (at least for one of the layers), which has the result that the JSONEncoder throws an error. I have no idea why the textField of one of the layers is nil under iOS 12 but not under iOS 15. But by changing the non-catchable "try!“ (line 28) into „try“ or "try?“ so that the App won’t crash with a runtime error anymore, the Map shows fine even under iOS 12 perfectly localized.

I have just made my first steps with the mapBox SDK, so I’m not that familar with all the details. Therefore I'm not really sure if the not-catchable „try!“ has a special purpose here. But it seems that if certain layers might not have all data set under all (older) iOS releases, this „try“ should be better „catchable“ to avoid such crashes.

@aclauss aclauss added the bug 🪲 Something is broken! label Dec 15, 2021
@ZiZasaurus ZiZasaurus self-assigned this Dec 16, 2021
@ZiZasaurus ZiZasaurus removed their assignment Feb 1, 2022
@macdrevx
Copy link
Contributor

My guess is that try JSONEncoder().encode(symbolLayer.textField) on line 86 is failing, not due to textField being nil, but rather due to JSONEncoder not supporting JSON fragments prior to iOS 13.

@macdrevx
Copy link
Contributor

Typically, text-field is an expression, which seems to avoid this issue since expressions serialize to arrays. So this crash would require being on iOS 11 or 12 and having a symbol layer with text-field set to a constant.

macdrevx added a commit that referenced this issue Apr 15, 2022
* Style.localizeLabels(into:forLayerIds:) crashed on iOS 11 and 12 if
  any of the symbol layers had text-field set to a constant.

Fixes #954
@macdrevx
Copy link
Contributor

Actually, text-field seems to always return an expression. Even if you set it with a constant string, that gets interpreted as a Formatted, and returned as such. So the crash criteria are actually iOS 11 or 12 and symbol layer with text-field == nil

@macdrevx macdrevx self-assigned this Apr 15, 2022
macdrevx added a commit that referenced this issue Apr 15, 2022
* Style.localizeLabels(into:forLayerIds:) crashed on iOS 11 and 12 if
  any of the symbol layers had text-field set to nil.

Fixes #954
macdrevx added a commit that referenced this issue Apr 15, 2022
* Style.localizeLabels(into:forLayerIds:) crashed on iOS 11 and 12 if
  any of the symbol layers had text-field set to nil.

Fixes #954
macdrevx added a commit that referenced this issue Apr 19, 2022
* Style.localizeLabels(into:forLayerIds:) crashed on iOS 11 and 12 if
  any of the symbol layers had text-field set to nil.

Fixes #954
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something is broken!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants