[Bug]: Crash on iOS: swift_isUniquelyReferenced_nonNull_native when using ChangeLineOffsetsShapeAnimator and MovePointShapeAnimator
Mapbox Implementation
Mapbox
Mapbox Version
11.12.5
React Native Version
0.74.7
Platform
iOS
@rnmapbox/maps version
10.1.38
Standalone component to reproduce
// ⚠️ NOT directly reproducible, example only.
// Crash happens in production when using experimental animators.
import React from 'react';
import Mapbox, {
MapView,
ShapeSource,
LineLayer,
Camera,
__experimental
} from '@rnmapbox/maps';
const line = {
type: 'LineString',
coordinates: [
[-74.00597, 40.71427],
[-74.00697, 40.71527],
],
};
export default function BugReportExample() {
// Example of using animators involved in crashes:
const moveAnimator = new __experimental.MovePointShapeAnimator([-74.00597, 40.71427]);
const offsetAnimator = new __experimental.ChangeLineOffsetsShapeAnimator({
coordinates: line.coordinates,
startOffset: 0,
endOffset: 0,
});
// In production, we call moveTo()/setEndOffset() repeatedly during animation
return (
<MapView style={{flex: 1}}>
<Camera centerCoordinate={[-74.00597, 40.71427]} zoomLevel={14} />
<ShapeSource id="line-source" shape={offsetAnimator}>
<LineLayer id="line-layer" />
</ShapeSource>
<ShapeSource id="point-source" shape={moveAnimator} />
</MapView>
);
}
Observed behavior and steps to reproduce
We’re seeing a production crash on iOS when frequently updating a ShapeSource via:
• __experimental.MovePointShapeAnimator.moveTo • __experimental.ChangeLineOffsetsShapeAnimator.setEndOffset
The crash is not currently reproducible in local/dev environments. It has only occurred on one production device so far, but the stack trace is consistent and always points inside Mapbox native code during updateGeoJSONSource.
Crash Stack Trace (same as screenshot):
Expected behavior
No response
Notes / preliminary analysis
No response
Additional links and references
No response
I'm guessing this is with old architecture? I try building something with new architecture even on 10.1.45 on iOS, and I get:
[TypeError: NativeRNMBXMovePointShapeAnimatorModule.default.generate is not a function (it is undefined)] errors at runtime (only on iOS).
@krisnaItsAVirus thanks much for the report, unfortunately without reproduction it's quite hard to look into this. Try playing with periodically and randomly calling moveTo and setEndOffset.
In your crash reported is in it the main thread? Do you have stack traces of other threads? Any other thread is in StyleSourceManager?
We might be calling updateGeoJSONSource from multiple threads, and mapbox might want it to be called from main thread, but it's not 100% clear to me. Another possibility is a race condition within mapbox libs, so a repro would be awesome.
https://github.com/mapbox/mapbox-maps-ios/blob/release/v11.16/Sources/MapboxMaps/Style/StyleSourceManager.swift
@krisnaItsAVirus thanks much for the report, unfortunately without reproduction it's quite hard to look into this. Try playing with periodically and randomly calling moveTo and setEndOffset.
In your crash reported is in it the main thread? Do you have stack traces of other threads? Any other thread is in StyleSourceManager?
We might be calling updateGeoJSONSource from multiple threads, and mapbox might want it to be called from main thread, but it's not 100% clear to me. Another possibility is a race condition within mapbox libs, so a repro would be awesome.
https://github.com/mapbox/mapbox-maps-ios/blob/release/v11.16/Sources/MapboxMaps/Style/StyleSourceManager.swift
@mfazekas Thanks for the response.
Is the crash on the main thread? Yes. The Sentry crash report shows that the crash occurs on the main thread, inside updateGeoJSONSource in StyleSourceManager. The top frames are in Swift (swift_isUniquelyReferenced_nonNull_native) and Mapbox’s Dictionary._Variant.setValue.
Stack traces of other threads: We don’t have evidence of other threads being involved. The Sentry report only shows the main thread. No other threads appear in the stack trace, and we haven’t seen any other thread accessing StyleSourceManager at the time of the crash.
Other thread in StyleSourceManager: Based on current reports, it looks like all ShapeSource updates happen on the main thread. There’s no indication that StyleSourceManager is being accessed concurrently from another thread in our app.
So far, this crash has only occurred once on a single production device, making it difficult to reproduce locally
I'm guessing this is with old architecture? I try building something with new architecture even on 10.1.45 on iOS, and I get:
[TypeError: NativeRNMBXMovePointShapeAnimatorModule.default.generate is not a function (it is undefined)]errors at runtime (only on iOS).
Yes, it's on old architecture.
@mfazekas, should I make a separate bug report for the code @krisnaItsAVirus posted in the OP that consistently crashes at runtime on iOS with [TypeError: NativeRNMBXMovePointShapeAnimatorModule.default.generate is not a function (it is undefined)] with new arch? I verified it works just fine in Android with that same code.
@devguy22 yes please open a new report esp if it something that can be reproduced