https://kotlinlang.org logo
Title
c

Colton Idle

02/02/2023, 6:40 PM
I'm getting a crash on a NPE as you can see below for like 1% of our users. I can't repro, but it seems like a race condition where our gmaps + gmaps manager isn't ready yet even though it gets init'd right when this screen is opened.
AnimatedVisibility(viewModel.screenState.showSelections) { <---- This defaults to false, so I don't understand of SlideUpCarouselScreen is called
      SlideUpCarouselScreen(googleMapManager!!) <!----- crash here for like 1% of our users
}
Is there a chance that even if
showSelections
is
false
by default, compose still runs the
SlideUpCarouselScreen(//)
line? I thought if showSelections is false, it just completely skips over the inside of AnimatedVisibility {}
a

Alex Vanyo

02/02/2023, 8:40 PM
When does
googleMapManager
get initialized or set back to
null
? And then same question for `showSelections`: can it go from
true
back to
false
?
s

Stylianos Gakis

02/02/2023, 9:01 PM
Since AnimatedVisibility will have a time from when showSelections is turned off that it will still show the contents, since it's animating of course, sounds like you're changing showSelections to false and at the same time turning googleMapManager to false, resulting in the crash as it's trying to animate out. You should be able to repro locally by doing exactly that, changing both at the exact same time and see the crash maybe? Maybe simply consider adding a null check instead of doing !! instead?
c

Colton Idle

02/03/2023, 4:23 AM
@Alex Vanyo the root of my screen is an AndroidView essentially
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colors.background) {
  AndroidView(
      factory = { context ->
        mapView.getMapAsync { googleMap ->
        //this is where i do stuff like get the googleMapManager
}
and it's never set back to null. So basically I try to get an instance ASAP. On top of the map theres a button, and that button toggle showSelection. So showSelection is false at first. So it's almost like
getMapAsync
actually could be slow and then someone clicks the button before that method is done? I think that's it. I feel kinda stupid that I didn't notice the getMapAsync stuff before, but maybe all of this makes sense now. :rubber_duck:
a

Alex Vanyo

02/04/2023, 12:50 AM
I was also thinking that if
showSelections
is held in a
ViewModel
, it could be
true
after some form of activity recreation before
googleMapManager
has had a chance to recreate.
c

Colton Idle

02/04/2023, 4:08 AM
gotcha. some people complaining in reviews have said its upon installation and open. but i'll look to see if a rotation could be the issue... thanks Alex and Stylianos