Skip to content

Commit

Permalink
[android][v10] Add guard to prevent NRE on map.getStyle().styleLayers (
Browse files Browse the repository at this point in the history
…#3595)

* Add guard to prevent NRE crashing android apps on launch of map without styleLayers being a valid array

* Update android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapView.kt

Use early return instead of optional chaining an iterator.

Co-authored-by: Miklós Fazekas <[email protected]>

---------

Co-authored-by: Frederick Engelhardt <[email protected]>
Co-authored-by: Miklós Fazekas <[email protected]>
  • Loading branch information
3 people authored Aug 27, 2024
1 parent 465d341 commit b96cdb9
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1129,8 +1129,15 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
Logger.e("MapView", "setSourceVisibility, map is null")
return
}
val style = mMap!!.getStyle();
style!!.styleLayers.forEach {
val style = mMap.getStyle();

val styleLayers = style?.styleLayers
if (styleLayers == null) {
Logger.e("MapView", "setSourceVisibility, map.getStyle().styleLayers is null")
return
}

styleLayers.forEach {
val layer = style.getLayer(it.id)
if ((layer != null) && match(layer, sourceId, sourceLayerId)) {
layer.visibility(
Expand Down

0 comments on commit b96cdb9

Please sign in to comment.