-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
fix: Fix accessing Frame
from multiple Threads by making it Thread-safe
#2327
Merged
Conversation
This file contains 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
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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.
What
Accessing
Frame
from multiple Threads was unsafe. The Frame could've been deallocated by now.With this PR, we check if the Frame is still valid and execute all unsafe methods under a
synchronized
block/Lock to make sure the app doesn't crash with null-unwrap errors.frame.isValid
The only property that will not throw when trying to access a closed frame is
isValid
:If you access any other property (e.g.
width
) on a closed Frame, it will throw an error:console.log(frame)
Since
console.log
is a function defined on the JS Thread only, calling it inside a Frame Processor will require a Thread hop - essentially doing arunOnJS
/Worklets.createRunInJSFunc
. When you pass theframe
to that function, it will transfer the Frame over to the JS Thread, and try to log the properties of the Frame later. The problem here is, that by the time theconsole.log
function tries to log theframe
, theframe
will already be deallocated since the Frame Processor has already finished it's execution in the meantime and a new Frame arrives.So this will throw an error:
Because the frame will be no longer valid when
console.log
runs.Instead, try this to debug Frames:
Java/Kotlin Changes
The Java/Kotlin
Frame
type brings two changes:frame.orientation
: This is no longer just aString
, but instead the actual type-safeOrientation
enum. This improves developer experience for native Java/Kotlin Frame Processor Pluginsframe.pixelFormat
: This is no longer just aString
, but instead the actual type-safePixelFormat
enum. This improves developer experience for native Java/Kotlin Frame Processor PluginsChanges
Tested on
Related issues