Fix crashes with SpriteJob(s) that weren't locking the doc correctly#4384
Merged
Conversation
aseprite-bot
left a comment
Collaborator
There was a problem hiding this comment.
clang-tidy made some suggestions
| newPalette->setEntry(i, tmpPalette.getEntry(j++)); | ||
| ++i; | ||
| } | ||
| int i = 0, j = 0; |
Collaborator
There was a problem hiding this comment.
warning: variable 'i' of type 'int' can be declared 'const' [misc-const-correctness]
int i = 0, j = 0;
^| ContextReader reader(context); | ||
| { | ||
| RotateJob job(reader, friendlyName(), m_angle, cels, rotateSprite); | ||
| RotateJob job(context, doc, friendlyName(), m_angle, cels, rotateSprite); |
Collaborator
There was a problem hiding this comment.
warning: variable 'job' of type 'RotateJob' can be declared 'const' [misc-const-correctness]
Suggested change
| RotateJob job(context, doc, friendlyName(), m_angle, cels, rotateSprite); | |
| RotateJob const job(context, doc, friendlyName(), m_angle, cels, rotateSprite); |
|
|
||
| { | ||
| SpriteSizeJob job(reader, new_width, new_height, resize_method); | ||
| SpriteSizeJob job(context, doc, new_width, new_height, resize_method); |
Collaborator
There was a problem hiding this comment.
warning: variable 'job' of type 'SpriteSizeJob' can be declared 'const' [misc-const-correctness]
Suggested change
| SpriteSizeJob job(context, doc, new_width, new_height, resize_method); | |
| SpriteSizeJob const job(context, doc, new_width, new_height, resize_method); |
…ix aseprite#4315) This was mainly found in SpriteSizeJob crash reports. In these reports deleted image buffers were still used to paint the Editor canvas because the doc was write-locked in the main thread (same thread where the canvas is painted). This produced a re-entrant lock in the Editor::onPaint() as we can still read-lock from the same thread where we write-locked the doc. With this change we write-lock the doc from the SpriteJob background thread (not the main thread) only if it's necessary (i.e. when the doc is not already locked in the main thread, e.g. when running a script). This makes that the main thread (Editor::onPaint) cannot read the doc until we finish the whole SpriteJob transaction/Tx.
45f4837 to
ec4e82b
Compare
This was referenced Sep 25, 2025
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.
This fixes #4315.