Repository navigation
fix(android): recover the location puck from a non-finite bearing - #4445
ajtrasatti wants to merge 1 commit into
Conversation
83da888 to
d1350fe
Compare
The Maps SDK location component keeps the last puck bearing it receives, including NaN or Infinity. The next time the puck layer is added, for example when LocationPuck settings change or its images load, addPersistentStyleLayer throws "IllegalArgumentException: Parse error at offset 165: Missing a colon after a name of object member." and the app crashes (mapbox/mapbox-maps-android#2340). RNMBXNativeUserLocation now applies its settings through LocationPuckGuard. When adding the puck layer fails, it resets the location component through LocationComponentManager, which drops the puck state holding the bad bearing, and applies once more. The reset holds the location provider while giving up location that is on (rnmapbox#4225) and is skipped while the map is stopped (mapbox/mapbox-maps-android#2017). If the reset is skipped or the retry fails too, the component stays disabled and the next puck apply resets it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
d1350fe to
421043d
Compare
mfazekas
left a comment
There was a problem hiding this comment.
Thanks for the detailed write-up and repro! For the path the reproducer exercises, the NaN enters through our own RNMBXCustomLocationProvider (updateHeading / registerLocationConsumer forward any heading to onBearingUpdated). Could we instead drop non-finite headings there? That fixes the crash at the source with a couple of lines and no recovery state machine. Does your production app use CustomLocationProvider, or the default device provider? If it's the default provider, we'd still prefer something much smaller than LocationPuckGuard. As written, the guard covers only RNMBXNativeUserLocation: Camera follow modes and LocationComponentManager still re-add the puck outside it. It also toggles location.enabled behind LocationComponentManager's back, so the manager's state can drift and re-enable the puck outside the guard. Please also trim the KDoc to a sentence or two plus the link to mapbox-maps-android#2340.
Description
On Android, re-applying
LocationPucksettings after the puck has received a NaN or Infinity bearing crashes the app atStyleManager.addPersistentStyleLayerwithIllegalArgumentException: Parse error at offset 165: Missing a colon after a name of object member.This is the Maps SDK bug mapbox/mapbox-maps-android#2340 and still reproduces with Maps SDK 11.33.0.RNMBXNativeUserLocationnow applies its settings throughLocationPuckGuard. When adding the puck layer fails, it resets the location component throughLocationComponentManagerand retries once, if location is requested and the map is running. Otherwise, or if the retry fails, it disables the component and resets it on the next puck apply while location is requested and the map is running. The reset holds the location provider (#4225); unrelated exceptions still propagate.Checklist
CONTRIBUTING.mdyarn generatein the root folder (no JS or API changes)/exampleapp./example) (bug fix; the reproducer is below)Testing
/examplerelease builds (New Architecture, Maps SDK 11.33.0) on an Android 11 x86 emulator, with the reproducer below:mainFATAL EXCEPTION … Parse error at offset 165Failed to add the location puck, disabled the location component …Mechanism and limits
LocationPuckManagerkeeps the last bearing it receives, NaN included, and its animator then stays at NaN. Re-applying puck settings re-adds the puck layer with that bearing.com.mapbox.bindgen.Value.toJson()swallows Gson's "Numeric values must be finite" and returns the half-written JSON, which ends in"bearing"at offset 165. The native parser rejects it.CustomLocationProviderreplays the NaN when the component re-registers, so the retry fails and the puck stays hidden until the heading is finite.Camerafollow modes andLocationComponentManagersettings changes still re-add the puck outside the guard. The proper fix is filtering non-finite values in the Maps SDK, as v10.20.0 did.Validation
./gradlew :rnmapbox_maps:testDebugUnitTestfromexample/android: 27/27, includingLocationPuckGuardTest(retry, stopped map, pending reset, unrelated exceptions) andLocationComponentResetTest(when the provider is held)./exampleassembleRelease -PreactNativeArchitectures=x86, API 30 Google APIs emulator, results in the table above.Component to reproduce the issue you're fixing
BugReportExample.js — tap "NaN heading", then "Change puck"