maplibre-react-native icon indicating copy to clipboard operation
maplibre-react-native copied to clipboard

Disable setting render mode if map is not fully ready

Open nsljivic93 opened this issue 7 months ago • 2 comments

The org.maplibre.reactnative.components.location throws error if the map style is not fully ready and we try to set render mode. Crash can happen if the Map is being unmounted, but render mode is being set. This fix is only for NativeUserLocation instance, and same fix might be appliable for other cases (LocationComponentManager.java). Same issue was reported here https://github.com/maplibre/maplibre-native/issues/2876 Fix is to check if map style is fully ready before doing the action.

nsljivic93 avatar Apr 11 '25 08:04 nsljivic93

Thank you for your contribution. Could you share a minimal reproduction, so we can see how the bug occurs?

KiwiKilian avatar Apr 11 '25 09:04 KiwiKilian

Shortest example is choosing Native render mode in the package react-native example: image image On our project minimal reproduction was:

  1. You have screen with a component containing Map and UserLocation
  2. As a part of optimisation, we want to hide user location when the component is not visible on the screen
  3. When navigating back from that screen, we register screen changed event before component will unmount.
  4. Now here the magic happens: UserLocation render mode is changing, and at the same time component unmounting (map ready becoming false). When render mode is about to change, style update in mapbox is happening on non-existant map - Attempt to invoke virtual method 'org.maplibre.android.maps.Style org.maplibre.android.maps.MapLibreMap.getStyle()' on a null object reference is fired.

The change above ignores this change if map is not ready. I hope I explained well. If you need more info, let me know. And thank you for maintaining this package.

nsljivic93 avatar May 02 '25 11:05 nsljivic93

First of all, are you using the old or new architecture?

I'm struggling to reproduce the bug. Could you please further explain, how to trigger it with the "Follow User Location Render Mode" example? Maybe provide a video?

I also don't fully understand your use case. Why would you unmount the map and change the render mode at the same time?

KiwiKilian avatar May 11 '25 23:05 KiwiKilian

Closing for missing response to my feedback. Happy to discuss further if my questions/concerns are adressed.

KiwiKilian avatar Oct 01 '25 04:10 KiwiKilian