CrossGeeks / GeofencePlugin

Geofence Plugin for Xamarin iOS and Android
MIT License
48 stars 22 forks source link

Crash in GeofenceImplementation.OnConnected callback NullReferenceException #24

Closed jasonmereckixpo closed 4 years ago

jasonmereckixpo commented 4 years ago

Our app has reported a crash, the exception is:

System.NullReferenceException: Object reference not set to an instance of an object

with the following stack trace:

GeofenceImplementation+<OnConnected>d__59.MoveNext ()
AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state)

Since this seems to happen inside the OnConnected method, I'm guessing the issue is that accessing var location = await mFusedLocationProviderClient.GetLastLocationAsync(); is the problem

https://github.com/CrossGeeks/GeofencePlugin/blob/b5de5e77e7666ae5b82a6d1d7891f87016dda2f1/src/Plugin.Geofence/GeofenceImplementation.android.cs#L524

Because the instance variable mFusedLocationProviderClient is only initialized in the IsLocationEnabled method:

https://github.com/CrossGeeks/GeofencePlugin/blob/b5de5e77e7666ae5b82a6d1d7891f87016dda2f1/src/Plugin.Geofence/GeofenceImplementation.android.cs#L149

Seems possible to have OnConnected executed by a thread before IsLocationEnabled is executed (or would be executed by a different thread).

rdelrosario commented 4 years ago

@jasonmereckixpo Thanks for fixing this issue.