ReactSlider crash on Android release version
See original GitHub issueThis issue was originally created by @ssg-luke as facebook/react-native#9979.
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
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top GitHub Comments
I believe the crash is caused by the custom Yoga
measure
implementation here: https://github.com/callstack/react-native-slider/blob/45c2a5438f0d7e2dd586a663c4043e795d6c1761/src/android/src/main/java/com/reactnativecommunity/slider/ReactSliderManager.java#L69That code runs on the Yoga layout thread, but it allocates a
ReactSlider
view. SinceReactSlider
extends AndroidSeekBar
, the constructor runs animation and drawable code on different thread than the main thread. I suspect this low-level Android view code is not thread-safe, and not designed to be run on a thread that is not the main thread.To prevent this code from executing, I changed the style for our
<ReactSlider>
to include a specificwidth
andheight
. This prevents Yoga from needing to measure the view. The crash no longer happens for our app.Hope this helps!
P.S. - I don’t know enough about Android view drawing and measurement to know how to implement the measure method without allocating a slider view. Maybe the measure could allocate the view on the main thread and block until that finishes?
I also have a similar bug with react-native 0.61.5. any update on this?