Skip to content

Fix initialisation of NodesManager #1030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2020
Merged

Conversation

jgonet
Copy link
Member

@jgonet jgonet commented Jul 27, 2020

Description

Previously, NodesManager registered (passing this) as an event listener before ending initialization in c-tor.

NodesManager is created by ReanimatedModule (when calling getNodesManager() for the first time) on UI thread.

When onEventDispatch() is called on non-UI thread it calls startUpdatingOnAnimationFrame(), which in turn uses mChoreographerCallback.
mChoreographerCallback is initialised after listener is registered which causes NPE in React Choreographer's postFrameCallback() method after trying adding callback to the queue.

Fixes #604.

References:
https://www.ibm.com/developerworks/java/library/j-jtp0618/index.html#2
https://stackoverflow.com/questions/25281301/what-exactly-are-the-dangers-of-passing-this-from-a-java-constructor

@jgonet jgonet requested a review from kmagiera July 27, 2020 12:56
@jgonet jgonet force-pushed the @kuba/fix-NPE-in-nodes-manager branch from 7126191 to fcafdc1 Compare July 27, 2020 13:35
@jgonet jgonet requested a review from jkadamczyk July 28, 2020 13:58
@jgonet jgonet self-assigned this Jul 29, 2020
@jgonet jgonet force-pushed the @kuba/fix-NPE-in-nodes-manager branch from 2227bdc to 02ae587 Compare August 11, 2020 09:48
@jgonet jgonet merged commit d3b6039 into v1 Aug 11, 2020
@jgonet jgonet deleted the @kuba/fix-NPE-in-nodes-manager branch August 11, 2020 10:03
jgonet added a commit that referenced this pull request Aug 12, 2020
Previously, `NodesManager` registered (passing `this`) as an event listener before ending initialization in c-tor.

`NodesManager` is created by `ReanimatedModule` (when calling `getNodesManager()` for the first time) on [UI thread](https://github.com/software-mansion/react-native-reanimated/blob/9af276693d136b712259fe9dd0126aee6c78bd4b/android/src/main/java/com/swmansion/reanimated/ReanimatedModule.java#L77-L80).

When `onEventDispatch()` is called on non-UI thread it calls `startUpdatingOnAnimationFrame()`, which in turn uses `mChoreographerCallback`.
`mChoreographerCallback` is initialised **after** listener is registered which causes NPE in React Choreographer's `postFrameCallback()` method after trying adding callback to the queue.

Fixes #604.

References:
https://www.ibm.com/developerworks/java/library/j-jtp0618/index.html#2
https://stackoverflow.com/questions/25281301/what-exactly-are-the-dangers-of-passing-this-from-a-java-constructor
kmagiera pushed a commit that referenced this pull request Aug 13, 2020

Unverified

This user has not yet uploaded their public signing key.
Previously, `NodesManager` registered (passing `this`) as an event listener before ending initialization in c-tor.

`NodesManager` is created by `ReanimatedModule` (when calling `getNodesManager()` for the first time) on [UI thread](https://github.com/software-mansion/react-native-reanimated/blob/9af276693d136b712259fe9dd0126aee6c78bd4b/android/src/main/java/com/swmansion/reanimated/ReanimatedModule.java#L77-L80).

When `onEventDispatch()` is called on non-UI thread it calls `startUpdatingOnAnimationFrame()`, which in turn uses `mChoreographerCallback`.
`mChoreographerCallback` is initialised **after** listener is registered which causes NPE in React Choreographer's `postFrameCallback()` method after trying adding callback to the queue.

Fixes #604.

References:
https://www.ibm.com/developerworks/java/library/j-jtp0618/index.html#2
https://stackoverflow.com/questions/25281301/what-exactly-are-the-dangers-of-passing-this-from-a-java-constructor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants