mapbox / mapbox/mapbox-maps-ios

Regression: EXC_BAD_ACCESS in 11.4.0 on iOS Simulator when calling `mapView.mapboxMap.cameraState`

Open
#2,187 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug :beetle:
Dominant language
Swift
Stars
601
Forks
196
PR merge metrics
No merged PRs in 30d

Description

## Environment

- Xcode version:15.4 (15F31d)
- iOS version: 17.5
- Devices affected: iOS Simulator (all virtual device types)
- Maps SDK Version: 11.4.0

## Observed behavior and steps to reproduce

When calling `map.mapboxMap.cameraState` on SDK 11.4.0 from the main thread in an iOS Simulator build, Mapbox crashes with EXC_BAD_ACCESS.

I'm running the following code:

```
struct RepresentedMapboxMapView : UIViewRepresentable
{
func makeUIView(context: Self.Context) -> MapboxMaps.MapView
{
// Set up the ``MapboxMaps.MapView``.
MapboxOptions.accessToken = AccessKeys.shared.mapboxAccessToken
let mapView = MapboxMaps.MapView(
frame: .zero,
mapInitOptions: .init(
cameraOptions: .init(center: CLLocationCoordinate2D(latitude: 40.0, longitude: -100.0), zoom: 3.0),
styleURI: .dark
)
)
try! mapView.mapboxMap.setProjection(.init(name: .mercator)) // Set 2D map projection

let maximumFPS = Float(UIScreen.main.maximumFramesPerSecond)
mapView.preferredFrameRateRange = .init(minimum: maximumFPS * 2 / 3, maximum: maximumFPS, preferred: maximumFPS)

runSynchronouslyOnMainThread {
let mapboxMapCameraState = mapView.mapboxMap.cameraState

// …
}

return mapView
}

func updateUIView(_ uiView: MapboxMaps.MapView, context: Context) {}
}

fileprivate func runSynchronouslyOnMainThread(_ body: () -> Void) {
if Thread.isMainThread {
body()
} else {
DispatchQueue.main.sync {
body()
}
}
}
```

In the observed crash, this code is already running on the main thread, so the `if Thread.isMainThread { body() }` condition of `runSynchronouslyOnMainThread` is taken.

## Expected behavior

Mapbox should not crash.

## Notes / preliminary analysis

Issue does not occur on-device, and does not occur in SDK 11.3.0 and earlier. Turning on Address Sanitizer, Thread Sanitizer, and/or Main Thread Check in the Xcode scheme reveals no additional warnings/info (probably because Xcode cannot analyze into the SDK's release-optimized xcframeworks).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Begin by reproducing the crash with the reported UIViewRepresentable snippet on an iOS Simulator using SDK 11.4.0, then compare the same cameraState access with SDK 11.3.0. Trace the MapboxMaps.MapView cameraState path available in the SDK and verify that the call no longer produces EXC_BAD_ACCESS on the simulator while preserving the on-device behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, swift
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.