react-native: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.facebook.react.uimanager.ReactShadowNode.setStyleWidth(float)' on a null object reference
Android tablet,when I assembleRelease the apk,modal view crash. debug not found this question.
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.facebook.react.uimanager.ReactShadowNode.setStyleWidth(float)' on a null object reference at com.facebook.react.uimanager.UIImplementation.updateNodeSize(UIImplementation.java:151) at com.facebook.react.uimanager.UIManagerModule.updateNodeSize(UIManagerModule.java:213) at com.facebook.react.views.modal.ReactModalHostView$DialogRootViewGroup$1.run(ReactModalHostView.java:302) at android.os.Handler.handleCallback(Handler.java:815) at android.os.Handler.dispatchMessage(Handler.java:104) at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31) at android.os.Looper.loop(Looper.java:194) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:196) at java.lang.Thread.run(Thread.java:818)
Additional Information
- React Native version: 0.36.1,0.37
- Platform: android
- Operating System: mac os
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 51
- Comments: 84 (13 by maintainers)
Commits related to this issue
- Fix crash if native code tries to update the size of a modal view after JS has removed it Summary: See https://github.com/facebook/react-native/issues/10845 onSizeChanged is enqueueing a runnable fr... — committed to facebook/react-native by astreet 7 years ago
- patch: setStyleWidth(float)' on a null Patch Error: ReactShadowNode.setStyleWidth(float)' on a null object reference facebook/react-native#10845 facebook/react-native@5873a22 — committed to gregberns/react-native by gregberns 7 years ago
- Fix crash if native code tries to update the size of a modal view after JS has removed it Summary: See https://github.com/facebook/react-native/issues/10845 onSizeChanged is enqueueing a runnable fr... — committed to facebook/react-native by astreet 7 years ago
- Fix crash if native code tries to update the size of a modal view after JS has removed it Summary: See https://github.com/facebook/react-native/issues/10845 onSizeChanged is enqueueing a runnable fr... — committed to frankrod/react-native by astreet 7 years ago
- Remove LoadingMask for now, since Modal got issue in Android of 0.42.3 https://github.com/facebook/react-native/issues/10845 — committed to ocleo1/react-native-lets-rock-poc by deleted user 6 years ago
Still happening on my side, without using any Modal (I am using react native navigation and its built-in Modal).
platform: Android (min api 21) react-native: 0.48.3
Not yet. This issue is the most popular 15th issue according to comments and still there is not any comment from the dev team since the beginning of this issue. This issue really caused tremendous frustration on my side.
Yeah, I’ll include it in next RC tomorrow.
Fix is in master now: https://github.com/facebook/react-native/commit/5873a228f41bca763c35c470375a9f3cb36f80ab
Looks like the commit didn’t end up in 0.43 release by a mistake. I have released a new version (0.43.3) along with some other smaller tweaks.
On Mon, 10 Apr 2017 at 07:16 tianxind notifications@github.com wrote:
Sorry for the lack of update, I was able to use the verify what was going wrong, I should have a fix landed to master in the next day or two.
Any updates?
@astreet Hey, I can consistently reproduce this with https://github.com/Cooke/ReactNativeAndroidModalCrashBug/
Hey everyone, sorry you’ve been having these crashes. Without being able to look at a repro, this looks like a race condition between the UI thread and the native modules (background) thread.
onSizeChanged
here is enqueueing a runnable from the ui thread that references a shadow view by id on the native modules thread. Since the shadow thread ‘runs ahead’ of the UI thread (e.g. it has a newer state of the world than the UI thread), this isn’t safe. By the time that code block runs, it’s possible that an update from JS has already removed that view from the shadow hierarchy (a change which would then propagate to the native hierarchy on the UI thread). I’m not sure off hand what is causingonSizeChanged
to be called, so it could also be something else though – e.g. the View in the hierarchy could not have an id set on it for some reason.I’ll try to see if I can get someone to look into it given the number of people affected.
I have manged to reproduce my version of this issue consistently and implemented a work-around (not battle-tested): https://github.com/Cooke/ReactNativeAndroidModalCrashBug/blob/master/index.android.js
+1 with version 0.40
@akzhou I solved this by using the InteractionManager runAfterInteractions in a ComponentDidMount, see below for further details:
https://github.com/brentvatne/run-after-interactions-exp/blob/master/index.js
Yeah this bug is pretty nasty, i’ve got 2 bad reviews in play store because of it … I’ve used this fix
Nothing fancy, but works okay
I am having the same issue. I have modal (fullscreen) and android keyboard on. It happens when I close it with enter key (onSubmitEditing). I’ve tried to close modal in
InteractionManager.runAfterInteractions
callback, but it didn’t help. However It seems to be working when I postpone it withsetTimeout(..., 300)
@grabbou This should be pretty safe to merge, what release can we get this into do you think?
I also have the same issue. I just added a delay of 1 sec before swaping to the view which solved this temporarily and there is no crash . This error is not encountered in debug mode, when we generate apk this error message pops up randomly. I believe it is due to react-native-router-flux
+1 for 0.41.2
Experiencing this randomly on startup as well. 0.4.0
I have the same question on React Native Version: 0.39.0 Platform: Android
I am experiencing the same issue. The only way I found to avoid the crash is wrapping the next action in a
setTimeout(..., 1000)
to give time to the modal to be dismissed.Maybe we should move this over to Canny, to gain visibility? https://react-native.canny.io/feature-requests
That’ll help the React team understand how many people are affected.
Of course, a consistent repro would go a long way towards us being able to figure out the right fix 😃
Note for anybody reading we solved our problem but in our case it had nothing to do with the Modal.
It was a problem with how we were using react-native-router-flux. We were not managing the scene stack properly. Using Actions.pop() correctly fixed our problem.
I have faced same issue and was able to get around.
I use a boolean to determine visibility of a modal (loading modal in my case). When this boolean value changes value quickly from false to true (modal visible) and true to false (modal invisible), this was causing the crash (probably it was not able to re-render quickly). So I gave a delay of 0.5 seconds before closing the modal and it worked.
Also, when you are debugging, you would not be able to reproduce this issue. As debugging gives enough time, crash wont be seen.
As this use case was taking too small time, there was no need to show loading modal in my case. So I just removed it.