-
Notifications
You must be signed in to change notification settings - Fork 56
[#424] Fix: app.rive.runtime.kotlin.core.errors.RiveException: Accessing disposed C++ object RiveArtboardRenderer. #429
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
Open
dabrosch
wants to merge
5
commits into
rive-app:master
Choose a base branch
from
dabrosch:dabrosch/issue-424
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+91
−121
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
21616f8
[#424] Fix: app.rive.runtime.kotlin.core.errors.RiveException: Access…
dabrosch 3028f5c
[#424] Cleanup / Optimizations for race condition fix
dabrosch d078c11
[#424] Added another check for isActive at the innermost lock context.
dabrosch 1afdd41
Merge branch 'master' into dabrosch/issue-424
dabrosch 106a089
[#424] Remove override of disposeDependencies since it should not als…
dabrosch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| package app.rive.runtime.kotlin.renderers | ||
|
|
||
| import androidx.annotation.VisibleForTesting | ||
| import androidx.annotation.WorkerThread | ||
| import app.rive.runtime.kotlin.controllers.RiveFileController | ||
| import app.rive.runtime.kotlin.core.Fit | ||
|
|
@@ -32,10 +31,7 @@ open class RiveArtboardRenderer( | |
| } | ||
|
|
||
| @WorkerThread | ||
| @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) | ||
| open fun resizeArtboard() { | ||
| if (!hasCppObject) return | ||
|
Comment on lines
-36
to
-37
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was not protected from race conditions because it didn't have the frameLock. |
||
|
|
||
| private fun resizeArtboard() { | ||
| if (fit == Fit.LAYOUT) { | ||
| val newWidth = width / scaleFactor | ||
| val newHeight = height / scaleFactor | ||
|
|
@@ -51,16 +47,29 @@ open class RiveArtboardRenderer( | |
| // Be aware of thread safety! | ||
| @WorkerThread | ||
| override fun draw() { | ||
| if (controller.requireArtboardResize.getAndSet(false)) { | ||
| synchronized(controller.file?.lock ?: this) { resizeArtboard() } | ||
| } | ||
|
|
||
| // Deref and draw under frameLock | ||
| synchronized(frameLock) { | ||
| // Early out for deleted renderer or inactive controller. | ||
| // Note: controller.isActive can change at any time, but | ||
| // hasCppObject can only change while holding frameLock | ||
| if (!hasCppObject || !controller.isActive) return | ||
|
|
||
| controller.activeArtboard?.draw(cppPointer, fit, alignment, scaleFactor = scaleFactor) | ||
| // Protect both resize and draw operations with file.lock to prevent race conditions | ||
| // with file/artboard changes on the UI thread. This matches the locking strategy | ||
| // used in controller.advance() | ||
| synchronized(controller.file?.lock ?: this) { | ||
| // No need to check hasCppObject again here. | ||
| if (!controller.isActive) return | ||
| if (controller.requireArtboardResize.getAndSet(false)) { | ||
| resizeArtboard() | ||
| } | ||
| controller.activeArtboard?.draw( | ||
| cppPointer, | ||
| fit, | ||
| alignment, | ||
| scaleFactor = scaleFactor | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -91,8 +100,4 @@ open class RiveArtboardRenderer( | |
| start() | ||
| } | ||
|
|
||
| override fun disposeDependencies() { | ||
| // Lock to make sure things are disposed in an orderly manner. | ||
| synchronized(controller.file?.lock ?: this) { super.disposeDependencies() } | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can try with lower numbers for the timeout, I just wanted to be safe.