Decide NativeAnimated backend per-instance instead of live flag (#57205)#57205
Closed
zeyap wants to merge 1 commit into
Closed
Decide NativeAnimated backend per-instance instead of live flag (#57205)#57205zeyap wants to merge 1 commit into
zeyap wants to merge 1 commit into
Conversation
|
@zeyap has exported this pull request. If you are a Meta employee, you can view the originating Diff in D108428720. |
…t#57205) Summary: ## Changelog: [Internal][Fixed] - Fix EXC_BAD_ACCESS / KERN_INVALID_ADDRESS in C++ Animated when `useSharedAnimatedBackend()` flips across a reused runtime C++ Animated chose between the legacy and shared-`AnimationBackend` code paths by reading `ReactNativeFeatureFlags::useSharedAnimatedBackend()` live, in many places. That flag is a process-global singleton (`ReactNativeFeatureFlags::accessor_`). On some app the global is reset and re-applied on every user switch (`FBReactModule setUpReactNativeFeatureFlags` -> `dangerouslyReset()`/`override()`), and the previous user's runtime is kept alive and reused. The shared `AnimationBackend` is attached only once, when an instance's `Scheduler` is constructed, gated on the flag at that moment. On a multi-account device the global flag could therefore read true on a reused instance whose backend was never attached, so `getOrCreate` took the shared path and dereferenced a null backend. It also let JS and C++ disagree, since JS caches the flag per runtime while C++ followed the mutated global. Fix: make the per-instance decision once and use it everywhere instead of the live flag. - `NativeAnimatedNodesManagerProvider::getOrCreate` selects the path by whether the shared `AnimationBackend` actually exists for this instance (`unstable_getAnimationBackend().lock() != nullptr`). - `NativeAnimatedNodesManager` stores a `const bool useSharedAnimatedBackend_`, latched in its constructor (true for the shared-backend ctor, false for the legacy ctor), and exposes it via `useSharedAnimatedBackend()`. All internal reads now use the member. - `PropsAnimatedNode` reads the decision through `manager_->useSharedAnimatedBackend()`. The attach side (`Scheduler`) is intentionally unchanged: it remains the single construction-time read that latches the per-instance decision the rest of the code now follows. This keeps JS and C++ consistent across global flag flips and removes the null dereference. Reviewed By: sbuggay Differential Revision: D108428720
|
This pull request has been merged in dd5c383. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary:
Changelog:
[Internal][Fixed] - Fix EXC_BAD_ACCESS / KERN_INVALID_ADDRESS in C++ Animated when
useSharedAnimatedBackend()flips across a reused runtimeC++ Animated chose between the legacy and shared-
AnimationBackendcode paths by readingReactNativeFeatureFlags::useSharedAnimatedBackend()live, in many places. That flag is a process-global singleton (ReactNativeFeatureFlags::accessor_). On some app the global is reset and re-applied on every user switch (FBReactModule setUpReactNativeFeatureFlags->dangerouslyReset()/override()), and the previous user's runtime is kept alive and reused. The sharedAnimationBackendis attached only once, when an instance'sScheduleris constructed, gated on the flag at that moment. On a multi-account device the global flag could therefore read true on a reused instance whose backend was never attached, sogetOrCreatetook the shared path and dereferenced a null backend. It also let JS and C++ disagree, since JS caches the flag per runtime while C++ followed the mutated global.Fix: make the per-instance decision once and use it everywhere instead of the live flag.
NativeAnimatedNodesManagerProvider::getOrCreateselects the path by whether the sharedAnimationBackendactually exists for this instance (unstable_getAnimationBackend().lock() != nullptr).NativeAnimatedNodesManagerstores aconst bool useSharedAnimatedBackend_, latched in its constructor (true for the shared-backend ctor, false for the legacy ctor), and exposes it viauseSharedAnimatedBackend(). All internal reads now use the member.PropsAnimatedNodereads the decision throughmanager_->useSharedAnimatedBackend().The attach side (
Scheduler) is intentionally unchanged: it remains the single construction-time read that latches the per-instance decision the rest of the code now follows. This keeps JS and C++ consistent across global flag flips and removes the null dereference.Reviewed By: sbuggay
Differential Revision: D108428720