software-mansion / react-native-reanimated

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

iOS: Full app crash #1284

Closed mrousavy closed 3 years ago

mrousavy commented 3 years ago

Description

I'm receiving the following error on iOS:

com.facebook.react.JavaScript (17): EXC_BAD_ACCESS (code=EXC_I386_GPFLT)

I've implemented a stories screen using react-native-navigation, and see this error when I quickly close the story (= unmount the screen) while (or shortly before) I run an animation with reanimated. In this case it's a withTiming worklet.

This is my call stack at the time of the crash:

Screenshots

Steps To Reproduce

  1. Create app using react-native-navigation and reanimated
  2. Open and close stories like a maniac
  3. At some point, close the story (and therefore unmount the screen) exactly when a worklet is being started, not sure it it's caused by a timing function, or the timing function having a callback and then unmounting the Reanimated View.

Expected behavior

I expect the story to close and any reanimated worklets/animations/state to be disposed

Actual behavior

The app crashes with the error com.facebook.react.JavaScript (17): EXC_BAD_ACCESS (code=EXC_I386_GPFLT)

Screenshot 2020-09-26 at 18 44 27

Snack or minimal code example

Working on this. Have to strip out a lot of things, not sure if I can easily replicate it using a simple example...

Package versions

Ghya commented 3 years ago

I have the same issue with a header, animated while scrolling But the same animation was working 2 days ago, before react-native upgrade (0.63.0 -> 0.63.2)

JB-CHAUVIN commented 3 years ago

Hello, same issue goes for me on RN 0.63.2 and Reanimated 2 Alpha 7.

Animated.ScrollView with scrollHandler and complex animation make the app freeze...

ajpaulingalls commented 3 years ago

I'm also getting an iOS app freeze when regular animations run alongside reanimations. Specifically, the main thread is stuck waiting for a semaphore on line 227 of REANodesManager.m, in the performOperations method:

dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
jpudysz commented 3 years ago

@Szymon20000 - I tested your fix from the master but issue still persists. Rewerting to @alpha.6 fixes the freezes

Szymon20000 commented 3 years ago

Hey guys! I need a minimal code example. It's hard to fix the problem without seeing it.

jpudysz commented 3 years ago

App freezes randomly, but I have one place where it's reproducible each time. Its rather a big app so if you are interested I can offer video call with screen sharing

Szymon20000 commented 3 years ago

@jpudysz Do you use Wix navigation?

jpudysz commented 3 years ago

No, my nagivation stack:

    "@react-navigation/native": "5.7.6",
    "@react-navigation/stack": "5.9.3",
mrousavy commented 3 years ago

@Szymon20000 I use wix navigation, but I don't really have a point where I can always reproduce it :/ I'll investigate this further.

Szymon20000 commented 3 years ago

@jpudysz Are you getting the same error and call stack as mentioned above?

jpudysz commented 3 years ago

No error, no crash, no logs in Xcode - but the app is frozen and not responding.

mrousavy commented 3 years ago

@jpudysz when the app is frozen hit the pause button in Xcode. Then show us your callstack. I might have experienced something similar, I always thought it was the navigation library's fault 🤔

Szymon20000 commented 3 years ago

Ok, I think the original problem has been solved by my fix. @jpudysz Your problem is probably caused by deadlock (probably because of our synchronous layout). I need a repo though. Your call stack will be also very helpful. @mrousavy Could you try our master build? https://docs.swmansion.com/react-native-reanimated/docs/installation#using-master-branch-builds (it should be available in 2.5 hours)

jpudysz commented 3 years ago

@mrousavy - after pause no additional logs, but I can confirm that problem is when I trigger animations + I'm calling navigate

mrousavy commented 3 years ago

@mrousavy Could you try our master build? https://docs.swmansion.com/react-native-reanimated/docs/installation#using-master-branch-builds (it should be available in 2.5 hours)

Isn't npm able to directly install from GitHub? Anyways, will try that, thanks!

kmagiera commented 3 years ago

when testing on iOS you can install directly from NPM because xcode can compile c++ code. This is not the case on Android where the standard Android dev setup does not include NDK (toolchain needed to compile c++ code). The master builds include compiled version of the reanimated library, but if you only want to do test builds with xcode you can compile the library from sources

mrousavy commented 3 years ago

@kmagiera I'm aware of that, I do have the NDK toolchain installed 👍

Only disadvantage is after every clean and rebuild I need to wait 3 years for it to build

Alexandredc commented 3 years ago

No error, no crash, no logs in Xcode - but the app is frozen and not responding.

Same problem here: no errors, no crash, no logs.

My app use react-native 0.63.2 ans react-reanimated ^2.0.0-alpha.7 The app freeze after a lot of toggling animation.

It only freeze on my physical device not on the IOS emulator.

I don't know how to help 😕.

JB-CHAUVIN commented 3 years ago

@jpudysz when the app is frozen hit the pause button in Xcode. Then show us your callstack. I might have experienced something similar, I always thought it was the navigation library's fault 🤔

Here is my stacktrace for the same problem : libsystem_kernel.dylibsemaphore_wait_trap: 0x11c7c5e2c <+0>: movq %rcx, %r10 0x11c7c5e2f <+3>: movl $0x1000024, %eax ; imm = 0x1000024 0x11c7c5e34 <+8>: syscall -> 0x11c7c5e36 <+10>: retq
0x11c7c5e37 <+11>: nop
`

I am using the latest version from the master branch (last COMMIT : https://github.com/software-mansion/react-native-reanimated/commit/ec5b3be4db62cc1f1b7c51bd251c81fd92d6dd97)

Here is the complete stacktrace when I go deeply : 1) image

2) image

3) image

4) image

5) image

JB-CHAUVIN commented 3 years ago

If I replace in the file REANodesManager.m line 228 : dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);

By : dispatch_semaphore_signal(semaphore);

It is working !

Is it bad ? Will it hurts my iPhone memory ? Can it break react-native-reanimated ? What do you think about it @Szymon20000 @jpudysz @mrousavy ?

Thanks for the reply, I hope we will find a solution...

drewandre commented 3 years ago

Looking forward to a solution for this as well. Unfortunately the freezing I've been experiencing in v2.0.0-alpha.7 is also mostly random, but for me it doesn't necessarily occur when navigating. The issue renders v2.0.0-alpha.7 unusable for me which is unfortunately because the caching fixes greatly improved my animation performance. I do have react-navigation installed but all the freezing occurs on the home screen when I have a somewhat complex animation running. In a separate project, navigating while animating (using a portal to animate an image to a new screen) almost always freezes the UI on v2.0.0-alpha.7 and I had to downgrade to v2.0.0-alpha-6.1 to fix this.

The one interaction I have that 100% always causes a full frozen UI (with no logs, crashes or anything) is when I scroll and then animate the layout of the scroll container. I'm happy to share this code, though it's a large project. I can try to slim it down in an example repo if anyone would like that.

Edit: I've attached a screenshot of my callstack when I hit pause in xcode. This is way over my head but I hope it helps :)

Screen Shot 2020-10-12 at 4 48 53 PM
Szymon20000 commented 3 years ago

We are almost sure what is causing the problem. We are working on it and should be solved soon.

Alexandredc commented 3 years ago

With ^2.0.0-alpha.8, it works great on my app which had this issue on beta ^2.0.0-alpha.7. Thanks for your awesome work ! 🎉

mrousavy commented 3 years ago

same, nice job @Szymon20000 👍🎉

kanelloc commented 3 years ago

Got the same error after updating xcode to version 13. Any ideas?

592da commented 2 years ago

Same as @kanelloc ,

xcode 13 RN 0.66 Reanimated 2.3.0-beta.2

?

princefishthrower commented 2 years ago

@kanelloc @592da - same thing here - app freezing on a specific (but not all) call to goBack() animation - did you figure out any fix here?