Fix possible segfault with Reanimated #71
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is my attempt to fix a segfault we were seeing in Detox. For reference, the segfault stack trace looks like this:
Stack trace
The app has crashed, see the details below:This was using Detox 20.17.0, Xcode 14.1, React Native 0.68.1, react-native-reanimated 1.13.4.
Anyway to explain the change, if you look in react-native-reanimated master branch or 1.13.4 in either case this method that DetoxSync is hooking
startUpdatingOnAnimationFrame
will lazily create aCADisplayLink
instance if one does not exist. But in DetoxSync as it stands today, it calls[self valueForKey:@"displayLink"]
before it calls the upstream-startUpdatingOnAnimationFrame:
from react-native-reanimated. This means it's possible theCADisplayLink
instance will not have been created yet, so the value returned is just some dangling pointer!This tiny PR just changes it so upstream
-startUpdatingOnAnimationFrame:
from react-native-reanimated is called first, before DetoxSync attempts to call[self valueForKey:@"displayLink"]
, ensuring that it's always lazily instantiated. I've tested it against our app and it fixes the segfault.