Skip to content

fix: prevent NullPointerException in RNMBXAtmosphere.addStyles()#4171

Open
zamausa wants to merge 2 commits intornmapbox:mainfrom
zamausa:fix/atmosphere-null-crash
Open

fix: prevent NullPointerException in RNMBXAtmosphere.addStyles()#4171
zamausa wants to merge 2 commits intornmapbox:mainfrom
zamausa:fix/atmosphere-null-crash

Conversation

@zamausa
Copy link
Contributor

@zamausa zamausa commented Mar 9, 2026

Description

Fix crash in RNMBXAtmosphere.addStyles() caused by non-null assertions (!!) on mReactStyle and mMap. When addStyles() is called before these properties are initialized (e.g. via setReactStyle() before addToMap()), the !! operator throws a NullPointerException.

Replaced with safe early-return null checks using Kotlin ?: patterns, consistent with how mAtmosphere is already guarded.

Checklist

  • I've read CONTRIBUTING.md
  • I updated the doc/other generated code with running yarn generate in the root folder
  • I have tested the new feature on /example app.
    • In V11 mode/ios
    • In New Architecture mode/ios
    • In V11 mode/android
    • In New Architecture mode/android
  • I added/updated a sample - if a new feature was implemented (/example)

Component to reproduce the issue you're fixing

Any usage of the <Atmosphere> component can trigger the crash when setReactStyle is called before the component is added to the map.

Replace non-null assertions (!!) on mReactStyle and mMap with safe early-return null checks to prevent crashes when addStyles() is called before these properties are initialized.
@zamausa zamausa temporarily deployed to CI with Mapbox Tokens March 9, 2026 22:59 — with GitHub Actions Inactive
@zamausa zamausa deployed to CI with Mapbox Tokens March 9, 2026 22:59 — with GitHub Actions Active
@zamausa zamausa temporarily deployed to CI with Mapbox Tokens March 9, 2026 22:59 — with GitHub Actions Inactive
@mfazekas
Copy link
Contributor

@zamausa thanks much for the PR, any chance you can include a small reproducer component?! To demo the issue?!

@zamausa zamausa requested a deployment to CI with Mapbox Tokens March 14, 2026 21:54 — with GitHub Actions Waiting
@zamausa zamausa requested a deployment to CI with Mapbox Tokens March 14, 2026 21:54 — with GitHub Actions Waiting
@zamausa zamausa requested a deployment to CI with Mapbox Tokens March 14, 2026 21:54 — with GitHub Actions Waiting
@zamausa
Copy link
Contributor Author

zamausa commented Mar 14, 2026

Thanks for the feedback! I added a small reproducer component to this PR.

mfazekas added a commit that referenced this pull request Mar 15, 2026
Two bugs fixed in RNMBXAtmosphere:

1. NPE in addStyles() when <Atmosphere /> is used with no props —
   mReactStyle!! throws NullPointerException because setReactStyle()
   is never called before addToMap(). Replaced !! with safe null
   early-returns. (related to PR #4171)

2. removeFromMap() was calling removeTerrain() instead of
   removeAtmosphere() (copy-paste bug), causing terrain to disappear
   when toggling Atmosphere off while the atmosphere itself stayed.
   Also now nulls mAtmosphere on removal for clean state.

Also adds atmosphere toggle + color cycling to TerrainSkyAtmosphere
and QueryTerrainElevation examples, and updates BugReportExampleTS
with the AtmosphereRaceRepro test case from PR #4171.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants