react-native: ReactSlider crash on Android release version
Issue Description
Hard crash randomly and unexpectedly on Android release version only (debug is fine, iOS is fine on both debug and release) when hiding and displaying sliders based on a state variable.
Steps to Reproduce / Code Snippets
We have a number of photo filters in our app which are selected by <TouchableOpacity>
components and some have a slider to adjust the blur or brightness etc. These sliders are completely separate from each other and are displayed based on a string stored in the components state called filter
.
Here is one such slider from render():
{filter === 'gamify' && ( <View style={styles.filterSlider}> <Text>How retro do you want to go?</Text> <Slider value={this.state.pixelSize} minimumValue={1} maximumValue={5} onValueChange={value => this.setState({pixelSize: value})} /> </View>)}
Expected Results
No crash when hiding and displaying sliders
Stack Trace
java.lang.NullPointerException: Attempt to write to field ‘java.util.ArrayList android.animation.AnimatorSet$Node.nodeDependents’ on a null object reference
Additional Information
- React Native version: 0.33
- Platform(s) (iOS, Android, or both?): Android (Release only)
- Operating System (macOS, Linux, or Windows?): Mac OSX
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 23
- Comments: 45 (2 by maintainers)
Commits related to this issue
- Disables StateListAnimator for React Slider Android 6 and 7 Summary: This diff disables the StateListAnimator for the ReactSlider component in Android 6 and 7 This is this is a hack to prevent T37452... — committed to facebook/react-native by mdvacca 6 years ago
- Disables StateListAnimator for React Slider Android 6 and 7 Summary: This diff disables the StateListAnimator for the ReactSlider component in Android 6 and 7 This is this is a hack to prevent T37452... — committed to michalchudziak/react-native-slider by mdvacca 6 years ago
Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we’re automatically closing issues after a period of inactivity. Please do not take it personally!
If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:
If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.
why closed? this crash is still not fix
Android 7.0 in production HUAWEI (VNS-L31) ReactNative 0.58
Caused by: java.lang.NullPointerException Attempt to read from field ‘android.animation.Animator android.animation.AnimatorSet$Node.mAnimation’ on a null object reference
@ShaMan123 You can try one of the workarounds I provided. It seems like there is a workaround being provided by the React Native team as well, but you might want to wait for a stable release. We used https://github.com/jeanregisser/react-native-slider as a alternative.
Can confirm that I’m still seeing this issue RN 0.52
I’ve been getting the same crash in AnimatorSet with a button created in a custom Android ViewManager, since at least 0.33. The crash is very rare relative to the number of times the view manager in question creates buttons, and happens in both release and debug on Android only.
The line in question is:
Button button = new Button(context);
(There is also an identical line in the shadow node which causes identical issues)
I can pretty much guarantee the crash occurring by wrapping the line above in a loop. I didn’t look into it deeply, but the nature of the problem and analysis of the code in AnimatorSet suggested it might be a threading issue. Sure enough, wrapping the line of code above in a block synchronized on something available to both the ViewManager and ShadowNode (e.g. the React context) eradicates the issue, although I assume the crash will still happen if code I don’t have control over also creates / inflates Buttons concurrently with mine. The line has to be synchronized in both the ViewManager and the ShadowNode.
Hopefully that narrows down the issue with the Slider and can help identify the root cause.
Reproduced on 0.55.2. I think that this is due to a race condition. In our situation we are moving to a next screen when you’ve set a value using the slider. This causes two things to happen at the same time: indicator/seek button becomes smaller with an animation, but the screen is also rerendering, thus removing the slider. My theory is that the slider is being removed and the animation is called after it, causing the NullPointerException. (It happens rarely though).
Possible workaround could be:
Simulator used: Nexus 5X with Android 7.0 and 7.1 and device: API 24 (7.0), 520x960 hdpi
Reproduced on 0.57.2 as well (Release Build) 😦
Android 7.0 in production Huawei (WAS-LX1A) React-Native 0.55.4
I m also facing the same problem, any one got this issue 's solution ?
Still here for us also. Happened a few days ago on HUAWEI KIW-L21, OS Level 23 WITH “react-native”: “0.48.2”
java.lang.NullPointerException: Attempt to write to field 'java.util.ArrayList android.animation.AnimatorSet$Node.nodeDependents' on a null object reference at android.animation.AnimatorSet.clone(AnimatorSet.java:700) at android.animation.AnimatorSet.clone(AnimatorSet.java:51) at android.animation.Animator$AnimatorConstantState.newInstance(Animator.java:562) at android.animation.Animator$AnimatorConstantState.newInstance(Animator.java:543) at android.content.res.ConstantState.newInstance(ConstantState.java:51) at android.content.res.ConstantState.newInstance(ConstantState.java:59) at android.content.res.ConfigurationBoundResourceCache.getInstance(ConfigurationBoundResourceCache.java:48) at android.animation.AnimatorInflater.loadAnimator(AnimatorInflater.java:111) at android.graphics.drawable.AnimatedVectorDrawable$AnimatedVectorDrawableState$PendingAnimator.newInstance(AnimatedVectorDrawable.java:567) at android.graphics.drawable.AnimatedVectorDrawable$AnimatedVectorDrawableState.inflatePendingAnimators(AnimatedVectorDrawable.java:545) at android.graphics.drawable.AnimatedVectorDrawable.applyTheme(AnimatedVectorDrawable.java:377) at android.graphics.drawable.DrawableContainer$DrawableContainerState.applyTheme(DrawableContainer.java:865) at android.graphics.drawable.DrawableContainer.applyTheme(DrawableContainer.java:577) at android.graphics.drawable.StateListDrawable.applyTheme(StateListDrawable.java:370) at android.graphics.drawable.AnimatedStateListDrawable.applyTheme(AnimatedStateListDrawable.java:391) at android.content.res.Resources.loadDrawable(Resources.java:4165) at android.content.res.Resources.loadDrawable(Resources.java:4006) at android.content.res.TypedArray.getDrawable(TypedArray.java:886) at android.content.res.XResources$XTypedArray.getDrawable(XResources.java:1372) at android.widget.AbsSeekBar.<init>(AbsSeekBar.java:194) at android.widget.SeekBar.<init>(SeekBar.java:85) at android.widget.SeekBar.<init>(SeekBar.java:81) at com.facebook.react.views.slider.ReactSlider.<init>(ReactSlider.java:56) at com.facebook.react.views.slider.ReactSliderManager.createViewInstance(ReactSliderManager.java:121) at com.facebook.react.views.slider.ReactSliderManager.createViewInstance(ReactSliderManager.java:39) at com.facebook.react.uimanager.ViewManager.createView(ViewManager.java:46) at com.facebook.react.uimanager.NativeViewHierarchyManager.createView(NativeViewHierarchyManager.java:218) at com.facebook.react.uimanager.UIViewOperationQueue$CreateViewOperation.execute(UIViewOperationQueue.java:150) at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.dispatchPendingNonBatchedOperations(UIViewOperationQueue.java:923) at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded(UIViewOperationQueue.java:895) at com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.java:31) at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:136) at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame(ChoreographerCompat.java:107) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:909) at android.view.Choreographer.doCallbacks(Choreographer.java:686) at android.view.Choreographer.doFrame(Choreographer.java:619) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:7407) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:133)