-
-
Notifications
You must be signed in to change notification settings - Fork 933
Description
Bug: Crash in dispatchCameraChangedEvent: due to missing null check on _eventEmitter (Fabric)
Environment:
@rnmapbox/maps^10.2.10- React Native 0.81.5 (New Architecture / Fabric)
- iOS 26.3 beta, iPhone 14 (iPhone14,5)
Description:
The app crashes with EXC_BAD_ACCESS (SIGSEGV) at KERN_INVALID_ADDRESS 0x20 when the Mapbox map view dispatches an onCameraChanged event after the React Native surface has already been torn down (e.g. when a CarPlay scene disconnects).
The crash occurs because dispatchCameraChangedEvent: in RNMBXMapViewComponentView.mm does not check whether _eventEmitter is null before using it. The Mapbox SDK continues to fire camera change callbacks asynchronously after the Fabric component view has been unmounted, at which point _eventEmitter is already nil.
maps/ios/RNMBX/RNMBXMapViewComponentView.mm
Line 122 in e171d95
| - (void)dispatchCameraChangedEvent:(NSDictionary*)event { |
Crash stack (abbreviated):
Thread 0 Crashed:
0 std::__1::weak_ptr<facebook::react::EventDispatcher const>::lock() const (EventEmitter.cpp:94)
1 facebook::react::EventEmitter::dispatchEvent(...)
2 facebook::react::EventEmitter::dispatchEvent(...) (EventEmitter.cpp:82)
3 facebook::react::RNMBXMapViewEventEmitter::onCameraChanged(...) (EventEmitters.cpp:100)
4 -[RNMBXMapViewComponentView dispatchCameraChangedEvent:] (RNMBXMapViewComponentView.mm:125)
5 -[RNMBXMapViewEventDispatcher sendEvent:] (RNMBXMapViewComponentView.mm:44)
6 closure #1 in RNMBXMapView.applyOnMapChange() (RNMBXMapView.swift:1120)
Root cause:
In RNMBXMapViewComponentView.mm, the other event handlers (onPress, onLongPress, onMapChange) all guard against a nil _eventEmitter:
if (strongSelf != nullptr && strongSelf->_eventEmitter != nullptr) { ... }But dispatchCameraChangedEvent: does not:
- (void)dispatchCameraChangedEvent:(NSDictionary*)event {
const auto [type, json] = RNMBXStringifyEventData(event);
std::dynamic_pointer_cast<const facebook::react::RNMBXMapViewEventEmitter>(self->_eventEmitter)->onCameraChanged({type, json});
}Suggested fix:
- (void)dispatchCameraChangedEvent:(NSDictionary*)event {
if (self->_eventEmitter == nullptr) {
return;
}
const auto [type, json] = RNMBXStringifyEventData(event);
std::dynamic_pointer_cast<const facebook::react::RNMBXMapViewEventEmitter>(self->_eventEmitter)->onCameraChanged({type, json});
}