Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes google map null pointer exception #1403

Merged
merged 1 commit into from
Jun 17, 2017

Conversation

chaitanya-bhagavan
Copy link
Contributor

@chaitanya-bhagavan chaitanya-bhagavan commented Jun 13, 2017

Sometimes AirMapView doDestroy is called before LifecycleEventListener onHostPause. This fixes #1358

AirMapView doDestroy is called before LifecycleEventListener onHostPause. This fixes react-native-maps#1358
@henrikra
Copy link

Do you have test phone that instantly crashes without this PR? So you can confirm that this works :)

@chaitanya-bhagavan
Copy link
Contributor Author

@henrikra This was crashing on my simulator with the same Nullpointer exception, some debugging led me to the bug. If you have access to a device to reproduce this issue then you can test it. It is a small change

@henrikra
Copy link

Unfortunately I don't have phone to reproduce this. But we definately need one

@IgorVanian
Copy link

This was actually a problem with my tablet (SAMSUNG T560 Android 4.4.4).
This fixed the crash on map load but it made the app unresponsive and after a couple of interactions, everything just freezes, maybe it has something to do with onPause()?

@chaitanya-bhagavan
Copy link
Contributor Author

@IgorVanian I dont think it has anything to do with onPause. This PR fixes a bug where sometimes AirMapView doDestroy (where MapView onDestroy is called) is called before the lifecycle onHostPause (where MapView onPause is called.). So AirMapView was trying to pause a MapView that is already destroyed, hence the NPE

@henrikra
Copy link

@chaitanya0bhagvan I think you need to get real device with this problem to really test this out.

@IgorVanian
Copy link

It works perfect on smartphones (it worked even without this PR). On my tablet it freezes when I tap on a marker to open my custom callout view (works on smartphones), but as I said, it fixed the original problem so maybe it's not related, or is it? :D

@chaitanya-bhagavan
Copy link
Contributor Author

chaitanya-bhagavan commented Jun 13, 2017

@henrikra I dont have access to any device to test this out. I guess since @IgorVanian has the device he might be able to test this out. @IgorVanian Can u write a simple react native app to reproduce this issue and then apply the fix to verify this PR fixes it ?

@IgorVanian
Copy link

Sure. Will do.

@henrikra
Copy link

@chaitanya0bhagvan Btw have you noticed that this #1273 tries to solve same problem as you?

@IgorVanian
Copy link

Cannot reproduce with a clean react-native init and vanilla react-native-maps (without this PR).
Maps are loading well without any error. I guess the execution is not slowed down by extra code thus methods are called correctly?

@henrikra
Copy link

@chaitanya0bhagvan Good news! We got actual phone to test which is LG G4. That device crashed instantly before. With this PR is does not crash and has been running on device without problems for 45min now!

We are going to try this in production this week. I will tell the results later :)

@chaitanya-bhagavan
Copy link
Contributor Author

@henrikra Good to hear. Glad I could be of help. @IgorVanian I have noticed that this is an intermittent issue, probably when the JS code is busy this is happening.

@chaitanya-bhagavan
Copy link
Contributor Author

@henrikra regarding #1273 you are right, this is PR solves the same problem. I will keep this open nevertheless, hope either one gets merged soon.

@henrikra
Copy link

@felipecsl Please check this PR. We are so close fixing this annoying issue

@henrikra
Copy link

@chaitanya0bhagvan This pr is now in production. I will report if it helps our users not to crash. So far no crashes ;)

@chaitanya-bhagavan
Copy link
Contributor Author

@henrikra Nice 👍

@felipecsl
Copy link
Contributor

This works as a palliative fix but we'll need to fix the underlying problem since we shouldn't have to do this in the first place

@henrikra
Copy link

Do you know what is the underlying problem? Btw full day without crashes in production for now :)

@henrikra
Copy link

2 days in production with this PR and now we got first crash. It is not exactly the same but very similar: (Xiaomi Redmi 4A)

java.lang.NullPointerException Attempt to invoke virtual method 'android.content.res.Resources com.google.maps.api.android.lib6.impl.aq.e()' on a null object reference 
    :com.google.android.gms.DynamiteModulesB:340 com.google.maps.api.android.lib6.gmm6.vector.ah.getResources
    ResolutionOverride.java:56 android.util.ResolutionOverride.<init>
    SurfaceView.java:207 android.view.SurfaceView.init
    SurfaceView.java:187 android.view.SurfaceView.<init>
    :com.google.android.gms.DynamiteModulesB:1 com.google.maps.api.android.lib6.gmm6.vector.am.<init>
    :com.google.android.gms.DynamiteModulesB:3 com.google.maps.api.android.lib6.gmm6.vector.ah.<init>
    :com.google.android.gms.DynamiteModulesB:53 com.google.maps.api.android.lib6.gmm6.api.am.<init>
    :com.google.android.gms.DynamiteModulesB:49 com.google.maps.api.android.lib6.gmm6.api.am.a
    :com.google.android.gms.DynamiteModulesB:38 com.google.android.gms.maps.internal.bv.a
    :com.google.android.gms.DynamiteModulesB:80 com.google.maps.api.android.lib6.impl.az.a
    :com.google.android.gms.DynamiteModulesB:1 com.google.maps.api.android.lib6.impl.az.a
    :com.google.android.gms.DynamiteModulesB:18 com.google.maps.api.android.lib6.impl.cw.a
    :com.google.android.gms.DynamiteModulesB:17 com.google.android.gms.maps.internal.t.onTransact
    Binder.java:387 android.os.Binder.transact
    Unknown:-1 com.google.android.gms.maps.internal.IMapViewDelegate$zza$zza.onCreate
    Unknown:-1 com.google.android.gms.maps.MapView$zza.onCreate
    Unknown:-1 com.google.android.gms.dynamic.zza$3.zzb
    Unknown:-1 com.google.android.gms.dynamic.zza$1.zza
    Unknown:-1 com.google.android.gms.maps.MapView$zzb.zzJz
    Unknown:-1 com.google.android.gms.maps.MapView$zzb.zza
    Unknown:-1 com.google.android.gms.dynamic.zza.zza
    Unknown:-1 com.google.android.gms.dynamic.zza.onCreate
    Unknown:-1 com.google.android.gms.maps.MapView.onCreate
    AirMapView.java:129 com.airbnb.android.react.maps.AirMapView.<init>
    AirMapManager.java:62 com.airbnb.android.react.maps.AirMapManager.createViewInstance
    AirMapManager.java:29 com.airbnb.android.react.maps.AirMapManager.createViewInstance
    ViewManager.java:46 com.facebook.react.uimanager.ViewManager.createView
    NativeViewHierarchyManager.java:218 com.facebook.react.uimanager.NativeViewHierarchyManager.createView
    UIViewOperationQueue.java:152 com.facebook.react.uimanager.UIViewOperationQueue$CreateViewOperation.execute
    UIViewOperationQueue.java:781 com.facebook.react.uimanager.UIViewOperationQueue$2.run
    UIViewOperationQueue.java:843 com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches
    UIViewOperationQueue.java:48 com.facebook.react.uimanager.UIViewOperationQueue.access$1600
    UIViewOperationQueue.java:815 com.facebook.react.uimanager.UIViewOperationQueue$3.runGuarded
    GuardedRunnable.java:21 com.facebook.react.bridge.GuardedRunnable.run
    Handler.java:739 android.os.Handler.handleCallback
    Handler.java:95 android.os.Handler.dispatchMessage
    Looper.java:148 android.os.Looper.loop
    ActivityThread.java:5437 android.app.ActivityThread.main
    Method.java:-2 java.lang.reflect.Method.invoke
    ZygoteInit.java:738 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
    ZygoteInit.java:628 com.android.internal.os.ZygoteInit.main

Any idea why this is happening?

@chaitanya-bhagavan
Copy link
Contributor Author

@henrikra It is crashing inside MapView.onCreate. Not sure what is happening.

@chaitanya-bhagavan
Copy link
Contributor Author

@henrikra I don't have any context as to what Felipe is talking about. I just started using react-native-maps and the very first time I tried it on the android simulator it crashed. I will probably try to understand what's going on if time permits.

@felipecsl
Copy link
Contributor

sorry for the vague comment. what I mean is that the very fact that we have to manage lifecycle events manually (by keeping a destroyed boolean field, for example) means that the whole thing is not behaving the way it should. More simply put, it means it's either leaking or not correctly handling the activity lifecycle, so these are palliative fixes to avoid crashes that shouldn't be there in the first place.
I'll try to get a cleanup started this weekend, in the meantime this PR should be a good stopgap.

@henrikra
Copy link

@felipecsl Could different Android operating systems call lifecycle methods in wrong order or something?

Good to hear you are getting started with this challenge :)

@felipecsl
Copy link
Contributor

@henrikra i dont think so, no. that's very unlikely.

@felipecsl felipecsl merged commit 8f30c8a into react-native-maps:master Jun 17, 2017
yosimasu pushed a commit to yosimasu/react-native-maps that referenced this pull request Jun 19, 2017
AirMapView doDestroy is called before LifecycleEventListener onHostPause. This fixes react-native-maps#1358
yosimasu pushed a commit to yosimasu/react-native-maps that referenced this pull request Jun 19, 2017
AirMapView doDestroy is called before LifecycleEventListener onHostPause. This fixes react-native-maps#1358
@7laria
Copy link

7laria commented Jun 30, 2017

Don't work for me

sorodrigo pushed a commit to Vizzuality/react-native-maps that referenced this pull request Jul 6, 2017
…-upstream

* upstream/master:
  Add minZoom and maxZoom properties for android and ios (react-native-maps#1360)
  Reference install solution in issue react-native-maps#718 in install docs (react-native-maps#1448)
  updates npm cache clean command (react-native-maps#1450)
  v0.15.3
  Added BatchedBridge
  Upgraded ios deps
  Use prop-types and add supprort for RN 0.45
  Allow react 16.0.0-alpha
  [Android] Code cleanup step I - reformatting (react-native-maps#1415)
  Fixes google map null pointer exception (react-native-maps#1403)
  [iOS - Google Maps] Fix animateToCoordinate and animateToRegion (react-native-maps#1115)
  Update from View.propTypes to ViewPropTypes to match RN v0.44.0 (react-native-maps#1323)
  Fix import header for React Native 0.44.2 (react-native-maps#1362)
  Fix a couple typos (react-native-maps#1375)
mikelambert added a commit to mikelambert/react-native-maps that referenced this pull request Jul 6, 2017
j8seangel added a commit to Vizzuality/react-native-maps that referenced this pull request Jul 14, 2017
* 'master' of github.com:Vizzuality/react-native-maps:
  fix: error syntax on AirMaps max and min zoom level not nil check
  Add minZoom and maxZoom properties for android and ios (react-native-maps#1360)
  Reference install solution in issue react-native-maps#718 in install docs (react-native-maps#1448)
  updates npm cache clean command (react-native-maps#1450)
  v0.15.3
  Added BatchedBridge
  Upgraded ios deps
  Use prop-types and add supprort for RN 0.45
  Allow react 16.0.0-alpha
  [Android] Code cleanup step I - reformatting (react-native-maps#1415)
  Fixes google map null pointer exception (react-native-maps#1403)
  [iOS - Google Maps] Fix animateToCoordinate and animateToRegion (react-native-maps#1115)
  Update from View.propTypes to ViewPropTypes to match RN v0.44.0 (react-native-maps#1323)
  Fix import header for React Native 0.44.2 (react-native-maps#1362)
  Fix a couple typos (react-native-maps#1375)
christopherdro pushed a commit that referenced this pull request Jul 27, 2017
yosimasu pushed a commit to yosimasu/react-native-maps that referenced this pull request Aug 7, 2017
sorodrigo pushed a commit to Vizzuality/react-native-maps that referenced this pull request Aug 21, 2017
* 'master' of https://github.com/airbnb/react-native-maps:
  v0.16.2
  Revert "Issue1176 improve ios marker performance by X100 (react-native-maps#1187)"
  Fix initial region android (react-native-maps#1563)
  v0.16.1
  Enhance Podfile. (react-native-maps#1252)
  Update marker component (react-native-maps#1428)
  Add legalNotice constant (react-native-maps#1458)
  Issue1176 improve ios marker performance by X100 (react-native-maps#1187)
  Fix initial region native prop (react-native-maps#1546)
  fix `Archive` configuration for iOS builds (react-native-maps#1550)
  v0.16.0
  Document MapView min/max zoom properties (react-native-maps#1538)
  Fix timing function used in AnimatedRegion.spring (react-native-maps#1479)
  Fix crashing the application when a user presses on the map and the Google Play Services need to be updated or at the moment of the process of updating (react-native-maps#1469)
  skip region monitoring if map object is null (react-native-maps#1443)
  Zoom level fixes (react-native-maps#1485)
  Attempt to fix crashes. A variant of react-native-maps#1403 but for another lifecycle method, as proposed by @Nelrohd. (react-native-maps#1464)
  Handle Android RN 0.47 breaking change (react-native-maps#1481)
  add MKTileOverlayRenderer (react-native-maps#1357)
  Add onMapReady callback (react-native-maps#1369)
pjaraherrera pushed a commit to pjaraherrera/react-native-maps that referenced this pull request Sep 27, 2017
AirMapView doDestroy is called before LifecycleEventListener onHostPause. This fixes react-native-maps#1358
pjaraherrera pushed a commit to pjaraherrera/react-native-maps that referenced this pull request Sep 27, 2017
markdgo pushed a commit to markdgo/react-native-maps that referenced this pull request Mar 15, 2021
…aps#1403 but for another lifecycle method, as proposed by @Nelrohd. (#1464)
NeymarJohn pushed a commit to NeymarJohn/React-Native-Chat that referenced this pull request Mar 29, 2021
…aps#1403 but for another lifecycle method, as proposed by @Nelrohd. (#1464)
MarcoAntonioAG pushed a commit to MarcoAntonioAG/React-map that referenced this pull request Mar 31, 2022
…aps#1403 but for another lifecycle method, as proposed by @Nelrohd. (#1464)
joshpeterson30489 added a commit to joshpeterson30489/maps-develop-with-react-native that referenced this pull request Sep 30, 2022
…aps#1403 but for another lifecycle method, as proposed by @Nelrohd. (#1464)
superstar1205 added a commit to superstar1205/Map-ReactNative that referenced this pull request Dec 26, 2022
…aps#1403 but for another lifecycle method, as proposed by @Nelrohd. (#1464)
anthony0506 added a commit to anthony0506/react-native-maps that referenced this pull request Mar 19, 2023
…aps#1403 but for another lifecycle method, as proposed by @Nelrohd. (#1464)
johney6767 pushed a commit to johney6767/Map-ReactNative that referenced this pull request May 31, 2023
…aps#1403 but for another lifecycle method, as proposed by @Nelrohd. (#1464)
GoldenDragon0710 added a commit to GoldenDragon0710/google-map-react-native that referenced this pull request Nov 27, 2023
…aps#1403 but for another lifecycle method, as proposed by @Nelrohd. (#1464)
PainStaker0331 pushed a commit to PainStaker0331/react-native-maps that referenced this pull request Mar 3, 2024
…aps#1403 but for another lifecycle method, as proposed by @Nelrohd. (#1464)
Super-CodeKing added a commit to Super-CodeKing/react_native_map that referenced this pull request Apr 26, 2024
…aps#1403 but for another lifecycle method, as proposed by @Nelrohd. (#1464)
fairskyDev0201 pushed a commit to fairskyDev0201/react-native-maps that referenced this pull request Apr 29, 2024
…aps#1403 but for another lifecycle method, as proposed by @Nelrohd. (#1464)
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.

Error invoking com.google.maps.api.android.lib6.impl.aq.e()
5 participants