React-native-fast-image: Android Preload Crash

Created on 14 Mar 2018  路  8Comments  路  Source: DylanVann/react-native-fast-image

Hi,

Some android users are experiencing crashes when trying to preload android.
here's the stacktrace from Fabric

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.Activity.runOnUiThread(java.lang.Runnable)' on a null object reference
       at com.dylanvann.fastimage.FastImageViewModule.preload(FastImageViewModule.java:36)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:374)
       at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:162)
       at com.facebook.react.bridge.queue.NativeRunnable.run(NativeRunnable.java)
       at android.os.Handler.handleCallback(Handler.java:751)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
       at android.os.Looper.loop(Looper.java:154)
       at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:194)
       at java.lang.Thread.run(Thread.java:761)

This is not happening for all users or all devices.
And doesn't seems to be the memory issue

Any idea how to go about fixing this?

Most helpful comment

@rochapablo I am also getting this on some devices. Specifically saw this coming from Nexus 5X. Any help?

All 8 comments

getCurrentActivity() returns null on that case. I guess for now (and since preloading is probably not a life / death matter) we can just null check the return value of it.

Until @DylanVann accepts (or not) my PR, you can use a fork I pushed to npm: https://www.npmjs.com/package/kh-react-native-fast-image

Checking for null activity has been merged, thank you @Kouznetsov

For future reference this seems to happen when a preload is called from JS, and then the native activity becomes null. In this case we just do not perform the preloading.

I'm still getting

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'com.bumptech.glide.Registry com.bumptech.glide.Registry.replace(java.lang.Class, java.lang.Class, com.bumptech.glide.load.model.ModelLoaderFactory)' on a null object reference
       at com.dylanvann.fastimage.FastImageOkHttpProgressGlideModule.registerComponents + 51(FastImageOkHttpProgressGlideModule.java:51)
       at com.bumptech.glide.GeneratedAppGlideModuleImpl.registerComponents + 37(GeneratedAppGlideModuleImpl.java:37)
       at com.bumptech.glide.Glide.initializeGlide + 269(Glide.java:269)
       at com.bumptech.glide.Glide.initializeGlide + 219(Glide.java:219)
       at com.bumptech.glide.Glide.checkAndInitializeGlide + 180(Glide.java:180)
       at com.bumptech.glide.Glide.get + 164(Glide.java:164)
       at com.bumptech.glide.Glide.getRetriever + 671(Glide.java:671)
       at com.bumptech.glide.Glide.with + 698(Glide.java:698)
       at com.dylanvann.fastimage.FastImageViewManager.createViewInstance + 50(FastImageViewManager.java:50)
       at com.dylanvann.fastimage.FastImageViewManager.createViewInstance + 32(FastImageViewManager.java:32)
       at com.facebook.react.uimanager.ViewManager.createView + 47(ViewManager.java:47)
       at com.facebook.react.uimanager.NativeViewHierarchyManager.createView + 256(NativeViewHierarchyManager.java:256)
       at com.facebook.react.uimanager.UIViewOperationQueue$CreateViewOperation.execute + 200(UIViewOperationQueue.java:200)
       at com.facebook.react.uimanager.UIViewOperationQueue$1.run + 911(UIViewOperationQueue.java:911)
       at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches + 1025(UIViewOperationQueue.java:1025)
       at com.facebook.react.uimanager.UIViewOperationQueue.access$2600 + 46(UIViewOperationQueue.java:46)
       at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded + 1085(UIViewOperationQueue.java:1085)
       at com.facebook.react.uimanager.GuardedFrameCallback.doFrame + 29(GuardedFrameCallback.java:29)
       at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame + 166(ReactChoreographer.java:166)
       at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame + 84(ChoreographerCompat.java:84)
       at android.view.Choreographer$CallbackRecord.run + 856(Choreographer.java:856)
       at android.view.Choreographer.doCallbacks + 670(Choreographer.java:670)
       at android.view.Choreographer.doFrame + 603(Choreographer.java:603)
       at android.view.Choreographer$FrameDisplayEventReceiver.run + 844(Choreographer.java:844)
       at android.os.Handler.handleCallback + 739(Handler.java:739)
       at android.os.Handler.dispatchMessage + 95(Handler.java:95)
       at android.os.Looper.loop + 148(Looper.java:148)
       at android.app.ActivityThread.main + 5421(ActivityThread.java:5421)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run + 726(ZygoteInit.java:726)
       at com.android.internal.os.ZygoteInit.main + 616(ZygoteInit.java:616)

This is how I call FastImage

return (
    <FastImage
    style={style}
    source={{
        priority: FastImage.priority.normal,
        uri: this.props.src,
    }}
    resizeMode={this.props.resizeMode || FastImage.resizeMode.contain}
    />
);

What exactly means _"this seems to happen when a preload is called from JS"_?

"react": "16.8.3",
"react-native": "0.59.5",
"react-native-fast-image": "^5.4.2",

@rochapablo I am also getting this on some devices. Specifically saw this coming from Nexus 5X. Any help?

Still nothing.

Getting this issue too:

RN-Version: 0.60.4

Device
Brand: LGE
Model: Nexus 5X
Orientation: Portrait
RAM free: 3.27 GB
Disk free: 1.98 GB

Operating System
Version: 6.0.1
Orientation: Portrait
Rooted: Yes

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'com.bumptech.glide.Registry com.bumptech.glide.Registry.replace(java.lang.Class, java.lang.Class, com.bumptech.glide.load.model.ModelLoaderFactory)' on a null object reference at com.dylanvann.fastimage.FastImageOkHttpProgressGlideModule.registerComponents + 51(FastImageOkHttpProgressGlideModule.java:51) at com.bumptech.glide.GeneratedAppGlideModuleImpl.registerComponents + 37(GeneratedAppGlideModuleImpl.java:37) at com.bumptech.glide.Glide.initializeGlide + 273(Glide.java:273) at com.bumptech.glide.Glide.initializeGlide + 223(Glide.java:223) at com.bumptech.glide.Glide.checkAndInitializeGlide + 184(Glide.java:184) at com.bumptech.glide.Glide.get + 168(Glide.java:168) at com.bumptech.glide.Glide.getRetriever + 689(Glide.java:689) at com.bumptech.glide.Glide.with + 716(Glide.java:716) at com.dylanvann.fastimage.FastImageViewManager.createViewInstance + 51(FastImageViewManager.java:51) at com.dylanvann.fastimage.FastImageViewManager.createViewInstance + 33(FastImageViewManager.java:33) at com.facebook.react.uimanager.ViewManager.createViewInstanceWithProps + 119(ViewManager.java:119) at com.facebook.react.uimanager.ViewManager.createViewWithProps + 66(ViewManager.java:66) at com.facebook.react.uimanager.NativeViewHierarchyManager.createView + 259(NativeViewHierarchyManager.java:259) at com.facebook.react.uimanager.UIViewOperationQueue$CreateViewOperation.execute + 198(UIViewOperationQueue.java:198) at com.facebook.react.uimanager.UIViewOperationQueue$1.run + 838(UIViewOperationQueue.java:838) at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches + 952(UIViewOperationQueue.java:952) at com.facebook.react.uimanager.UIViewOperationQueue.access$2200 + 44(UIViewOperationQueue.java:44) at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded + 1012(UIViewOperationQueue.java:1012) at com.facebook.react.uimanager.GuardedFrameCallback.doFrame + 29(GuardedFrameCallback.java:29) at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame + 172(ReactChoreographer.java:172) at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame + 84(ChoreographerCompat.java:84) at android.view.Choreographer$CallbackRecord.run + 856(Choreographer.java:856) at android.view.Choreographer.doCallbacks + 670(Choreographer.java:670) at android.view.Choreographer.doFrame + 603(Choreographer.java:603) at android.view.Choreographer$FrameDisplayEventReceiver.run + 844(Choreographer.java:844) at android.os.Handler.handleCallback + 739(Handler.java:739) at android.os.Handler.dispatchMessage + 95(Handler.java:95) at android.os.Looper.loop + 148(Looper.java:148) at android.app.ActivityThread.main + 5421(ActivityThread.java:5421) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run + 726(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main + 616(ZygoteInit.java:616)

Also getting this with Nexus 5X

Was this page helpful?
0 / 5 - 0 ratings