mapbox-maps-ios icon indicating copy to clipboard operation
mapbox-maps-ios copied to clipboard

Swift 6 support

Open richardpineo opened this issue 1 year ago • 8 comments

Environment

  • Xcode version: Xcode 16 beta 5
  • iOS version: 17.x, 18 beta
  • Devices affected: iPad
  • Maps SDK Version: 11.5.2

Observed behavior and steps to reproduce

When compiling and running with Swift 6, the mapbox SDK crashes reliably when downloading tile regions and style packs using the OfflineManager.

It appears to me that Mapbox iOS SDK is not compatible with Swift 6 compilation.

Expected behavior

The SDK should be able to be used with an app compiled using Swift 6.

Notes / preliminary analysis

It looks to me to opt out of Swift 6 until support is ready, Mapbox would need to follow these steps: https://www.swift.org/migration/documentation/swift-6-concurrency-migration-guide/swift6mode/

I'm don't have a deep understanding of creating and supporting packages so it could be that something else is required or that I am goofing something on my end.

Additional links and references

The call stack isn't very meaningful to me but using breakpoints it is clear that calling loadTileRegion or loadStylePack is the proximate location of the crash.

I can't be sure from this but it looks like maybe there was some error in downloading the tile region in this case and reporting the error is the thing that crashed? Not sure.

com.mapbox.common.Unspecified Worker 1 (24): EXC_BREAKPOINT (code=1, subcode=0x101050448)

in: internal func coreAPIClosureAdapter<T, SwiftError, ObjCType>(

0 ??? 0x000000011ef089d4 0x0 + 4814047700 1 FlightPulse-App 0x0000000100528000 __debug_blank_executor_main + 0 2 libdispatch.dylib 0x00000001010503d0 dispatch_assert_queue_fail + 0 3 libswift_Concurrency.dylib 0x00000001a7febb58 64890F8C-83E3-3941-B7A4-12FFAB6F3116 + 404312 4 FlightPulse-App.debug.dylib 0x00000001065a56d8 $s15FlightPulse_App24MapboxOfflineTileRegionsC08downloadF6Region33_337409C8DD1D1326470AACBCBB9FA0E7LL9stylePack7airport7optionsyAA0de5StyleQ10IdentifierV_AA7AirportVAA0dE15DownloadOptionsVtYaFyScCyyts5NeverOGXEfU_ys6ResultOySo07MBXTileI0Cs5Error_pGcfU + 508 5 FlightPulse-App.debug.dylib 0x0000000107d47a64 $ss6ResultOySo13MBXTileRegionCs5Error_pGIegg_AFIegn_TR + 40 () $R0 = {}

6 FlightPulse-App.debug.dylib 0x0000000107d41214 $s10MapboxMaps21coreAPIClosureAdapter3for4type17concreteErrorType9converterySo11MBXExpectedCyq0_04CoreiJ0Qy_GSgcys6ResultOyxs0I0_pGc_q0_mq_mxSgq0_ctAA0mI13RepresentableR_Rl0_CAJRLCr1_lFyALcfU_ + 348 7 FlightPulse-App.debug.dylib 0x0000000107d412ec $s10MapboxMaps21coreAPIClosureAdapter3for4type17concreteErrorType9converterySo11MBXExpectedCyq0_04CoreiJ0Qy_GSgcys6ResultOyxs0I0_pGc_q0_mq_mxSgq0_ctAA0mI13RepresentableR_Rl0_CAJRLCr1_lFyALcfU_TA + 84 8 FlightPulse-App.debug.dylib 0x0000000107d47c24 $sSo11MBXExpectedCySo13MBXTileRegionCSo0bC5ErrorCGIegg_AGIeyBy_TR + 64 9 MapboxCommon 0x00000001016865ec _ZN6mapbox7bindgen6mapbox6common22TileRegionLoadProgress5toCppEP25MBXTileRegionLoadProgress + 15164 10 MapboxCommon 0x00000001016a1bc4 _ZN6mapbox6common16TileStoreFactory11replaceImplENSt3__110unique_ptrINS1_4ImplENS2_14default_deleteIS4_EEEE + 5544 11 MapboxCommon 0x00000001016a4678 _ZN6mapbox6common16TileStoreFactory11replaceImplENSt3__110unique_ptrINS1_4ImplENS2_14default_deleteIS4_EEEE + 16476 12 MapboxCommon 0x00000001016a85ec _ZN6mapbox6common16TileStoreFactory11replaceImplENSt3__110unique_ptrINS1_4ImplENS2_14default_deleteIS4_EEEE + 32720 13 MapboxCommon 0x00000001016abcac _ZN6mapbox6common16TileStoreFactory11replaceImplENSt3__110unique_ptrINS1_4ImplENS2_14default_deleteIS4_EEEE + 46736 14 MapboxCommon 0x0000000101562a40 _ZN6mapbox6common25SystemInformationProvider20getSystemInformationEv + 11544 15 libsystem_pthread.dylib 0x0000000223b4037c _pthread_start + 136 16 libsystem_pthread.dylib 0x0000000223b3b494 thread_start + 8

richardpineo avatar Aug 09 '24 16:08 richardpineo

Hey @richardpineo may you clarify which Xcode version do you use and does this crash happens only on iPad devices or others also affected? In you case it looks like a DispatchQueue assert failing, can it be the case that you call loadTileRegion/loadStylePack and then try to do some UI related actions without switching to MainThread as callbacks from OfflineManager can be scheduled to non-main thread?

aleksproger avatar Aug 19 '24 07:08 aleksproger

Hey, @richardpineo is the issue still relevant or you found some workaround?

aleksproger avatar Sep 02 '24 08:09 aleksproger

I was able to reproduce the issue with the similar stacktrace and as I suspected the crash happens when I start manipulating UI from the callback without switching to main thread beforehand. So, most likely you may resolve the issue by calling the code inside the callback on main thread with DispatchQueue.main.async {...}. Here is the similar problem in Swift forum post where the owner of new concurrency model confirmed this behaviour. I'll close the issue, however feel free to reopen it if it doesn't help

aleksproger avatar Sep 04 '24 07:09 aleksproger

My apologies, I did not see this response somehow. I think I assumed that I would be notified, although I could have sworn I have checked several times in the last yer.

Anyway, i'm not sure I agree with this analysis. I can reproduce the crash reliably using loadTileRegion. The function will work as expected on success, but crash when handling an error.

I stripped down the call to the bare minimum:

await withCheckedContinuation { continuation in
	let cancelable = tileStore.loadTileRegion(forId: identifier.regionId, loadOptions: tileRegionLoadOptions) { [weak self] _ in
	        continuation.resume()
	}
}

The contents of my load options or the ID don't seem problematic - especially since this same code works reliably in Swift 5.

Putting a breakpoint on the line with continuation.resume() is not hit before the crash. The location of the crash is here:

Image

So, I don't think the issue lies in the callback handler.

I'd love to connect and try to work together to solve this as it is the only issue which is blocking us from updating to Swift 6.

@aleksproger I do not have privileges to reopen this ticket. Can we work together to try to solve this?

My email is Richard.E.Pineo at geaerospace.com if that helps.

richardpineo avatar Sep 09 '25 16:09 richardpineo

Can confirm that I see this crash as well when compiling with Swift 6 (Xcode 16.4) in version 11.15.0.

johankool avatar Sep 12 '25 14:09 johankool

Is it possible to reopen this issue? I cannot do it:

Image

richardpineo avatar Sep 12 '25 17:09 richardpineo

Bump

richardpineo avatar Oct 21 '25 18:10 richardpineo

This runtime error occurs with .swiftLanguageMode(.v5), too - as soon as you activate

.enableUpcomingFeature("DynamicActorIsolation")

or

.enableUpcomingFeature("StrictConcurrency")

or both in Package.swift of your module.

Xcode is Version 26.0.1 (17A400)

SPM module has // swift-tools-version: 6.2

agugel avatar Oct 24 '25 08:10 agugel