software-mansion / react-native-reanimated

React Native's Animated library reimplemented
https://docs.swmansion.com/react-native-reanimated/
MIT License
9.05k stars 1.31k forks source link

First touch with `Gesture.Pan()` crashes Android after installing `react-native-reanimated`, even with no imports from the library #3826

Closed jsindos closed 1 year ago

jsindos commented 1 year ago

Description

My React Native app on Android is dying upon first touch with a Gesture.Pan() after installing react-native-reanimated. It works fine beforehand.

I am not explicitly importing react-native-reanimated anywhere in the application.

I have included 'react-native-reanimated/plugin' in babel.config.js.

I cleaned cache before running the project.

I have a RectButton from react-native-gesture-handler elsewhere in my project which doesn't crash the app upon interaction.

Output from adb logcat as the crash occurs:

12-01 12:47:30.069 27243 27243 F libc    : Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 27243 (turepanbugsnack), pid 27243 (turepanbugsnack)
12-01 12:47:30.194 27354 27354 I crash_dump64: obtaining output fd from tombstoned, type: kDebuggerdTombstoneProto
12-01 12:47:30.194   688   688 I tombstoned: received crash request for pid 27243
12-01 12:47:30.195 27354 27354 I crash_dump64: performing dump of process 27243 (target tid = 27243)
12-01 12:47:30.379 27354 27354 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
12-01 12:47:30.380 27354 27354 F DEBUG   : Build fingerprint: 'google/oriole/oriole:13/TP1A.221005.002/9012097:user/release-keys'
12-01 12:47:30.380 27354 27354 F DEBUG   : Revision: 'MP1.0'
12-01 12:47:30.380 27354 27354 F DEBUG   : ABI: 'arm64'
12-01 12:47:30.380 27354 27354 F DEBUG   : Timestamp: 2022-12-01 12:47:30.202910805+1100
12-01 12:47:30.380 27354 27354 F DEBUG   : Process uptime: 8s
12-01 12:47:30.380 27354 27354 F DEBUG   : Cmdline: com.jsindos.gesturepanbugsnack
12-01 12:47:30.380 27354 27354 F DEBUG   : pid: 27243, tid: 27243, name: turepanbugsnack  >>> com.jsindos.gesturepanbugsnack <<<
12-01 12:47:30.380 27354 27354 F DEBUG   : uid: 10271
12-01 12:47:30.380 27354 27354 F DEBUG   : tagged_addr_ctrl: 0000000000000001 (PR_TAGGED_ADDR_ENABLE)
12-01 12:47:30.380 27354 27354 F DEBUG   : signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
12-01 12:47:30.380 27354 27354 F DEBUG   :     x0  0000000000000000  x1  0000000000006a6b  x2  0000000000000006  x3  0000007ffa5c8530
12-01 12:47:30.380 27354 27354 F DEBUG   :     x4  0000000000000000  x5  0000000000000000  x6  0000000000000000  x7  0000000000000000
12-01 12:47:30.380 27354 27354 F DEBUG   :     x8  00000000000000f0  x9  00000079959339e0  x10 0000000000000001  x11 00000079959745e0
12-01 12:47:30.380 27354 27354 F DEBUG   :     x12 0000007ffa5c7038  x13 0000000000000000  x14 0000000000000004  x15 0000000000000004
12-01 12:47:30.380 27354 27354 F DEBUG   :     x16 00000079959e1d58  x17 00000079959bd120  x18 000000799d3a8000  x19 0000000000006a6b
12-01 12:47:30.380 27354 27354 F DEBUG   :     x20 0000000000006a6b  x21 00000000ffffffff  x22 ffffff8005a3712f  x23 0000007ffa5c8790
12-01 12:47:30.380 27354 27354 F DEBUG   :     x24 0000007ffa5c8ed0  x25 0000000000000000  x26 0000000000000001  x27 0000007ffa5c8ed0
12-01 12:47:30.380 27354 27354 F DEBUG   :     x28 0000007ffa5c8dd0  x29 0000007ffa5c85b0
12-01 12:47:30.380 27354 27354 F DEBUG   :     lr  00000079959650c8  sp  0000007ffa5c8510  pc  00000079959650f4  pst 0000000000001000
12-01 12:47:30.380 27354 27354 F DEBUG   : backtrace:
12-01 12:47:30.380 27354 27354 F DEBUG   :       #00 pc 00000000000530f4  /apex/com.android.runtime/lib64/bionic/libc.so (abort+164) (BuildId: cbc4c62a9b269839456f1d7728d8411e)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #01 pc 00000000000af7e4  /data/app/~~h2D7HsxvWsVGmwkz--3NYg==/com.jsindos.gesturepanbugsnack-FInuNe-TzbE0aA1zBfc8tA==/lib/arm64/libc++_shared.so (BuildId: ece72a2ebc3774a1be9fd21271258acd3bcdfaa7)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #02 pc 00000000000aedc8  /data/app/~~h2D7HsxvWsVGmwkz--3NYg==/com.jsindos.gesturepanbugsnack-FInuNe-TzbE0aA1zBfc8tA==/lib/arm64/libc++_shared.so (BuildId: ece72a2ebc3774a1be9fd21271258acd3bcdfaa7)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #03 pc 00000000000aebf8  /data/app/~~h2D7HsxvWsVGmwkz--3NYg==/com.jsindos.gesturepanbugsnack-FInuNe-TzbE0aA1zBfc8tA==/lib/arm64/libc++_shared.so (__gxx_personality_v0+200) (BuildId: ece72a2ebc3774a1be9fd21271258acd3bcdfaa7)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #04 pc 0000000000226b18  /data/app/~~h2D7HsxvWsVGmwkz--3NYg==/com.jsindos.gesturepanbugsnack-FInuNe-TzbE0aA1zBfc8tA==/lib/arm64/libreanimated.so (BuildId: 4967b8142b80ebc9bdaeba6f5758d940794b5a66)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #05 pc 0000000000226bd4  /data/app/~~h2D7HsxvWsVGmwkz--3NYg==/com.jsindos.gesturepanbugsnack-FInuNe-TzbE0aA1zBfc8tA==/lib/arm64/libreanimated.so (BuildId: 4967b8142b80ebc9bdaeba6f5758d940794b5a66)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #06 pc 00000000001e1320  /data/app/~~h2D7HsxvWsVGmwkz--3NYg==/com.jsindos.gesturepanbugsnack-FInuNe-TzbE0aA1zBfc8tA==/lib/arm64/libreanimated.so (reanimated::Scheduler::triggerUI()+136) (BuildId: 4967b8142b80ebc9bdaeba6f5758d940794b5a66)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #07 pc 00000000001e6784  /data/app/~~h2D7HsxvWsVGmwkz--3NYg==/com.jsindos.gesturepanbugsnack-FInuNe-TzbE0aA1zBfc8tA==/lib/arm64/libreanimated.so (reanimated::AndroidScheduler::triggerUI()+36) (BuildId: 4967b8142b80ebc9bdaeba6f5758d940794b5a66)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #08 pc 00000000001eb0ec  /data/app/~~h2D7HsxvWsVGmwkz--3NYg==/com.jsindos.gesturepanbugsnack-FInuNe-TzbE0aA1zBfc8tA==/lib/arm64/libreanimated.so (facebook::jni::detail::MethodWrapper<void (reanimated::AndroidScheduler::*)(), &(reanimated::AndroidScheduler::triggerUI()), reanimated::AndroidScheduler, void>::dispatch(facebook::jni::alias_ref<facebook::jni::detail::JTypeFor<facebook::jni::HybridClass<reanimated::AndroidScheduler, facebook::jni::detail::BaseHybridClass>::JavaPart, facebook::jni::JObject, void>::_javaobject*>)+160) (BuildId: 4967b8142b80ebc9bdaeba6f5758d940794b5a66)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #09 pc 00000000001eb158  /data/app/~~h2D7HsxvWsVGmwkz--3NYg==/com.jsindos.gesturepanbugsnack-FInuNe-TzbE0aA1zBfc8tA==/lib/arm64/libreanimated.so (facebook::jni::detail::CallWithJniConversions<void (*)(facebook::jni::alias_ref<facebook::jni::detail::JTypeFor<facebook::jni::HybridClass<reanimated::AndroidScheduler, facebook::jni::detail::BaseHybridClass>::JavaPart, facebook::jni::JObject, void>::_javaobject*>), void, facebook::jni::detail::JTypeFor<facebook::jni::HybridClass<reanimated::AndroidScheduler, facebook::jni::detail::BaseHybridClass>::JavaPart, facebook::jni::JObject, void>::_javaobject*>::call(facebook::jni::detail::JTypeFor<facebook::jni::HybridClass<reanimated::AndroidScheduler, facebook::jni::detail::BaseHybridClass>::JavaPart, facebook::jni::JObject, void>::_javaobject*, void (*)(facebook::jni::alias_ref<facebook::jni::detail::JTypeFor<facebook::jni::HybridClass<reanimated::AndroidScheduler, facebook::jni::detail::BaseHybridClass>::JavaPart, facebook::jni::JObject, void>::_javaobject*>))+52) (BuildId: 4967b8142b80ebc9bdaeba6f5758d940794b5a66)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #10 pc 00000000001eafb8  /data/app/~~h2D7HsxvWsVGmwkz--3NYg==/com.jsindos.gesturepanbugsnack-FInuNe-TzbE0aA1zBfc8tA==/lib/arm64/libreanimated.so (facebook::jni::detail::FunctionWrapper<void (*)(facebook::jni::alias_ref<facebook::jni::detail::JTypeFor<facebook::jni::HybridClass<reanimated::AndroidScheduler, facebook::jni::detail::BaseHybridClass>::JavaPart, facebook::jni::JObject, void>::_javaobject*>), facebook::jni::detail::JTypeFor<facebook::jni::HybridClass<reanimated::AndroidScheduler, facebook::jni::detail::BaseHybridClass>::JavaPart, facebook::jni::JObject, void>::_javaobject*, void>::call(_JNIEnv*, _jobject*, void (*)(facebook::jni::alias_ref<facebook::jni::detail::JTypeFor<facebook::jni::HybridClass<reanimated::AndroidScheduler, facebook::jni::detail::BaseHybridClass>::JavaPart, facebook::jni::JObject, void>::_javaobject*>))+44) (BuildId: 4967b8142b80ebc9bdaeba6f5758d940794b5a66)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #11 pc 00000000001e6f10  /data/app/~~h2D7HsxvWsVGmwkz--3NYg==/com.jsindos.gesturepanbugsnack-FInuNe-TzbE0aA1zBfc8tA==/lib/arm64/libreanimated.so (facebook::jni::detail::MethodWrapper<void (reanimated::AndroidScheduler::*)(), &(reanimated::AndroidScheduler::triggerUI()), reanimated::AndroidScheduler, void>::call(_JNIEnv*, _jobject*)+36) (BuildId: 4967b8142b80ebc9bdaeba6f5758d940794b5a66)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #12 pc 0000000000440554  /apex/com.android.art/lib64/libart.so (art_quick_generic_jni_trampoline+148) (BuildId: d307dc6adc4105b5e392ad710770385d)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #13 pc 000000000020a2b0  /apex/com.android.art/lib64/libart.so (nterp_helper+4016) (BuildId: d307dc6adc4105b5e392ad710770385d)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #14 pc 0000000000030344  [anon:dalvik-classes2.dex extracted in memory from /data/app/~~h2D7HsxvWsVGmwkz--3NYg==/com.jsindos.gesturepanbugsnack-FInuNe-TzbE0aA1zBfc8tA==/base.apk!classes2.dex] (com.swmansion.reanimated.Scheduler$1.run+28)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #15 pc 000000000020b074  /apex/com.android.art/lib64/libart.so (nterp_helper+7540) (BuildId: d307dc6adc4105b5e392ad710770385d)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #16 pc 0000000000030384  [anon:dalvik-classes2.dex extracted in memory from /data/app/~~h2D7HsxvWsVGmwkz--3NYg==/com.jsindos.gesturepanbugsnack-FInuNe-TzbE0aA1zBfc8tA==/base.apk!classes2.dex] (com.swmansion.reanimated.Scheduler$2.runGuarded+12)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #17 pc 000000000020a254  /apex/com.android.art/lib64/libart.so (nterp_helper+3924) (BuildId: d307dc6adc4105b5e392ad710770385d)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #18 pc 00000000002e8404  [anon:dalvik-classes.dex extracted in memory from /data/app/~~h2D7HsxvWsVGmwkz--3NYg==/com.jsindos.gesturepanbugsnack-FInuNe-TzbE0aA1zBfc8tA==/base.apk] (com.facebook.react.bridge.GuardedRunnable.run+0)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #19 pc 000000000020b074  /apex/com.android.art/lib64/libart.so (nterp_helper+7540) (BuildId: d307dc6adc4105b5e392ad710770385d)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #20 pc 0000000000474eac  /system/framework/framework.jar (android.os.Handler.handleCallback+4)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #21 pc 0000000000209334  /apex/com.android.art/lib64/libart.so (nterp_helper+52) (BuildId: d307dc6adc4105b5e392ad710770385d)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #22 pc 0000000000474d00  /system/framework/framework.jar (android.os.Handler.dispatchMessage+8)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #23 pc 0000000002010b74  /memfd:jit-cache (deleted) (android.os.Looper.loopOnce+1444)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #24 pc 0000000000209a9c  /apex/com.android.art/lib64/libart.so (nterp_helper+1948) (BuildId: d307dc6adc4105b5e392ad710770385d)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #25 pc 000000000049783a  /system/framework/framework.jar (android.os.Looper.loop+162)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #26 pc 0000000000209334  /apex/com.android.art/lib64/libart.so (nterp_helper+52) (BuildId: d307dc6adc4105b5e392ad710770385d)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #27 pc 00000000001bb64a  /system/framework/framework.jar (android.app.ActivityThread.main+202)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #28 pc 0000000000436e00  /apex/com.android.art/lib64/libart.so (art_quick_invoke_static_stub+576) (BuildId: d307dc6adc4105b5e392ad710770385d)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #29 pc 0000000000469534  /apex/com.android.art/lib64/libart.so (_jobject* art::InvokeMethod<(art::PointerSize)8>(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jobject*, _jobject*, unsigned long)+1960) (BuildId: d307dc6adc4105b5e392ad710770385d)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #30 pc 0000000000468d64  /apex/com.android.art/lib64/libart.so (art::Method_invoke(_JNIEnv*, _jobject*, _jobject*, _jobjectArray*) (.__uniq.165753521025965369065708152063621506277)+48) (BuildId: d307dc6adc4105b5e392ad710770385d)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #31 pc 00000000002d1148  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (art_jni_trampoline+120)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #32 pc 000000000020a2b0  /apex/com.android.art/lib64/libart.so (nterp_helper+4016) (BuildId: d307dc6adc4105b5e392ad710770385d)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #33 pc 00000000003f71ae  /system/framework/framework.jar (com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run+22)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #34 pc 0000000000d4a8d8  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (com.android.internal.os.ZygoteInit.main+3464)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #35 pc 0000000000436e00  /apex/com.android.art/lib64/libart.so (art_quick_invoke_static_stub+576) (BuildId: d307dc6adc4105b5e392ad710770385d)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #36 pc 0000000000582718  /apex/com.android.art/lib64/libart.so (art::JValue art::InvokeWithVarArgs<_jmethodID*>(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jmethodID*, std::__va_list)+900) (BuildId: d307dc6adc4105b5e392ad710770385d)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #37 pc 00000000005f611c  /apex/com.android.art/lib64/libart.so (art::JNI<true>::CallStaticVoidMethodV(_JNIEnv*, _jclass*, _jmethodID*, std::__va_list)+160) (BuildId: d307dc6adc4105b5e392ad710770385d)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #38 pc 00000000000bbce8  /system/lib64/libandroid_runtime.so (_JNIEnv::CallStaticVoidMethod(_jclass*, _jmethodID*, ...)+120) (BuildId: cdeba1221151b65963e03a70a805dff9)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #39 pc 00000000000c7bf8  /system/lib64/libandroid_runtime.so (android::AndroidRuntime::start(char const*, android::Vector<android::String8> const&, bool)+840) (BuildId: cdeba1221151b65963e03a70a805dff9)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #40 pc 0000000000002560  /system/bin/app_process64 (main+1280) (BuildId: 6f97a590777bd06f31784c7272763a35)
12-01 12:47:30.380 27354 27354 F DEBUG   :       #41 pc 000000000004b500  /apex/com.android.runtime/lib64/bionic/libc.so (__libc_init+96) (BuildId: cbc4c62a9b269839456f1d7728d8411e)
12-01 12:47:30.391   688   688 E tombstoned: Tombstone written to: tombstone_22
12-01 12:47:30.394  1837 27358 I DropBoxManagerService: add tag=data_app_native_crash isTagEnabled=true flags=0x2
12-01 12:47:30.394  1837 27357 W ActivityTaskManager:   Force finishing activity com.jsindos.gesturepanbugsnack/.MainActivity

Steps to reproduce

npm i react-native-reanimated@^2.13.0 react-native-gesture-handler@2.8.0

import { Animated, Dimensions } from 'react-native'
import { Gesture, GestureDetector } from 'react-native-gesture-handler'
import { useState } from 'react'

const { width } = Dimensions.get('window')

export default ({ navigation }) => {
  const translate = new Animated.ValueXY({ x: 0, y: 0 })
  const translateX = translate.x.interpolate({
    inputRange: [-(width / 2), width / 2],
    outputRange: [-(width / 2), width / 2],
    extrapolateLeft: 'clamp',
    extrapolateRight: 'clamp'
  })

  const [currentX, setCurrentX] = useState(0)

  const panGesture = Gesture.Pan()
    .onUpdate((e) => {
      translate.setValue({ x: e.translationX + currentX, y: 0 })
    })
    .onEnd((e) => {
      setCurrentX(e.translationX + currentX)
    })

  return (
    <GestureDetector gesture={panGesture}>
      <Animated.View
        height={width / 1.5}
        width={width}
        style={{ position: 'absolute', zIndex: 1, transform: [{ translateX }], backgroundColor: '#000' }}
      />
    </GestureDetector>
  )
}

Snack or a link to a repository

https://github.com/jsindos/gesture-pan-bug-snack

Reanimated version

2.13.0

React Native version

0.69.6

Platforms

Android

JavaScript runtime

No response

Workflow

Expo bare workflow

Architecture

No response

Build type

No response

Device

Real device

Device model

Google Pixel 6

Acknowledgements

Yes

j-piasecki commented 1 year ago

Gesture Handler will detect and use Reanimated when you have it installed even without explicitly using it. In this case the gesture callbacks are automatically workletized and run on the UI thread. You can use .runOnJS(true) modifier to prevent it from happening, i.e.:

const panGesture = Gesture.Pan()
    .runOnJS(true)
    .onUpdate((e) => {
      translate.setValue({ x: e.translationX + currentX, y: 0 })
    })
    .onEnd((e) => {
      setCurrentX(e.translationX + currentX)
    })
jsindos commented 1 year ago

@j-piasecki Thanks for responding. So I take it you can only certain commands in a worklet, and running any code in the context of regular Animated from react-native will cause a crash?

kostas64 commented 1 year ago

I had a similar problem. When i using a gesture detector and runOnJS for state functions the app was freezing, but chaining e.g the gesture.pan() with runOnJS(true) solved my problem.

j-piasecki commented 1 year ago

@jsindos That's correct. Inside a worklet you can only call other worklets, calling another function directly (without runOnJS) will result in a crash.

bhagwasiyaritu commented 1 year ago

Gesture Handler will detect and use Reanimated when you have it installed even without explicitly using it. In this case the gesture callbacks are automatically workletized and run on the UI thread. You can use .runOnJS(true) modifier to prevent it from happening, i.e.:

const panGesture = Gesture.Pan()
    .runOnJS(true)
    .onUpdate((e) => {
      translate.setValue({ x: e.translationX + currentX, y: 0 })
    })
    .onEnd((e) => {
      setCurrentX(e.translationX + currentX)
    })

You Saved my day...