React-native-reanimated: iOS: Full app crash

Created on 26 Sep 2020  路  24Comments  路  Source: software-mansion/react-native-reanimated

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

  • React: 16.13.1
  • React Native: 0.63.2
  • React Native Reanimated: 2.0.0-alpha7
  • React Native Navigation: 7.0.0-snapshot2020
馃彔 Reanimated2 馃悶 Bug

Most helpful comment

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

All 24 comments

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)

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...

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);

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

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

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

@jpudysz Do you use Wix navigation?

No, my nagivation stack:

    "@react-navigation/native": "5.7.6",
    "@react-navigation/stack": "5.9.3",

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

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

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

@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 馃

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)

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

@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!

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

@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

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 馃槙.

@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

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...

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

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

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 ! 馃帀

same, nice job @Szymon20000 馃憤馃帀

Was this page helpful?
0 / 5 - 0 ratings