Skip to content

Fix crashes with SpriteJob(s) that weren't locking the doc correctly#4384

Merged
dacap merged 1 commit into
aseprite:mainfrom
dacap:fix-crash-on-sprite-job
Mar 25, 2024
Merged

Fix crashes with SpriteJob(s) that weren't locking the doc correctly#4384
dacap merged 1 commit into
aseprite:mainfrom
dacap:fix-crash-on-sprite-job

Conversation

@dacap

@dacap dacap commented Mar 25, 2024

Copy link
Copy Markdown
Member

This fixes #4315.

@dacap dacap self-assigned this Mar 25, 2024

@aseprite-bot aseprite-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

newPalette->setEntry(i, tmpPalette.getEntry(j++));
++i;
}
int i = 0, j = 0;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Comment thread src/app/commands/cmd_sprite_size.cpp Outdated

{
SpriteSizeJob job(reader, new_width, new_height, resize_method);
SpriteSizeJob job(context, doc, new_width, new_height, resize_method);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@dacap dacap force-pushed the fix-crash-on-sprite-job branch from 45f4837 to ec4e82b Compare March 25, 2024 21:53
@dacap dacap marked this pull request as ready for review March 25, 2024 22:53
@dacap dacap merged commit ec4e82b into aseprite:main Mar 25, 2024
@dacap dacap deleted the fix-crash-on-sprite-job branch March 25, 2024 22:54
@dacap dacap added this to the v1.3.6 milestone Mar 25, 2024
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.

Crash rendering image/renderPlan

2 participants