mapbox / mapbox-maps-ios

Interactive, thoroughly customizable maps for iOS powered by vector tiles and Metal
https://www.mapbox.com/mapbox-mobile-sdk
Other
462 stars 150 forks source link

Swift 6 support #2224

Closed richardpineo closed 1 week ago

richardpineo commented 1 month ago

Environment

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_ys6ResultOySo07MBXTileI0Cs5ErrorpGcfU + 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_CAJRLCr1lFyALcfU + 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 _ZN6mapbox6common16TileStoreFactory11replaceImplENSt3110unique_ptrINS1_4ImplENS2_14default_deleteIS4_EEEE + 5544 11 MapboxCommon 0x00000001016a4678 _ZN6mapbox6common16TileStoreFactory11replaceImplENSt3110unique_ptrINS1_4ImplENS2_14default_deleteIS4_EEEE + 16476 12 MapboxCommon 0x00000001016a85ec _ZN6mapbox6common16TileStoreFactory11replaceImplENSt3110unique_ptrINS1_4ImplENS2_14default_deleteIS4_EEEE + 32720 13 MapboxCommon 0x00000001016abcac _ZN6mapbox6common16TileStoreFactory11replaceImplENSt3110unique_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

aleksproger commented 3 weeks ago

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 commented 1 week ago

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

aleksproger commented 1 week ago

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