Skip to content

ashift: don't drop the deferred autocrop on an early preview signal - #22332

Merged
TurboGit merged 3 commits into
darktable-org:masterfrom
kofa73:fix/ashift-lost-deferred-autocrop
Sep 19, 2026
Merged

TurboGit merged 3 commits into
darktable-org:masterfrom
kofa73:fix/ashift-lost-deferred-autocrop

Conversation

@kofa73

@kofa73 kofa73 commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator

Fixes #21513

Problem

If rotate and perspective is still disabled when its rotation is changed (for example with an r+scroll shortcut, before the module is in the history), gui_changed() has no preview buffer yet. It therefore defers the automatic crop until a preview has finished. The preview-finished signal can come from a run that started before the module was enabled. The callback cleared the request, do_crop() returned early on the empty buffer, and the crop was lost. The image stayed rotated with empty corners, in the lighttable and in exports, until the next adjustment.

master, burst of 5 r+scroll steps 3.6 s after opening, uncropped wedge at the top:
r5_3 6

Fix

The preview callback now leaves the crop request pending while g->buf is still empty, so the first preview run that fills the buffer does the crop. Otherwise nothing changes. It also no longer adds a history item for a crop that did not happen.

same timing with the fix, race hit, crop applied:
f7

This is independent of #22198 (#21918, unlocked buffer geometry reads). Both touch ashift.c. The new check reads buf_width/buf_height the same way as the surrounding master code, so whichever PR merges second should switch it to _get_buf_geometry().

Testing

Linux, Release build, CPU only. darktable running in headless sway, with the input sent by a script.

  • master: scrolling while the initial preview was still running lost the crop in 2 of 2 attempts.
  • With the fix: 8 runs at the same timing. The race occurred once, and the crop was applied on the next preview. All 8 results were cropped.
  • A burst with 100 ms between steps still crops after every step.

Not tested: OpenCL, and the integration tests (no cv2 here; this path runs only with the GUI). I only reproduced the case where the module starts out disabled. The original report does not say whether that applies to it.

Code, commits, PR by Claude Code.

@piratenpanda

Copy link
Copy Markdown
Contributor

Nice, I encountered this several times :)

@anoderay

Copy link
Copy Markdown
Collaborator

Tested: Fixes the issue. Thanks!

@TurboGit TurboGit added this to the 5.8 milestone Sep 19, 2026
@TurboGit TurboGit added bugfix pull request fixing a bug scope: image processing correcting pixels labels Sep 19, 2026

@TurboGit TurboGit left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The preview geometry check must be synchronized to avoid races with preview updates.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes a race in ashift where deferred automatic cropping could be lost before preview geometry was available.

Changes:

  • Keeps crop requests pending until preview geometry is available.
  • Documents the fix in the release notes.
File Summary
src/​iop/​ashift.c Defers cropping when preview dimensions are unavailable.
RELEASE_NOTES.md Documents the automatic-crop fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/iop/ashift.c Outdated
@kofa73

kofa73 commented Sep 19, 2026 •

Copy link
Copy Markdown
Collaborator Author
  • Let me get Claude at all to check
  • Valid, on it (and there's a bit more).

A rotation change made while the module is still disabled defers the
autocrop until the preview buffer exists. A preview-finished signal
from a run that started before the module was enabled cleared the
request, do_crop() bailed out on the empty buffer, and the crop was
lost. Keep the request pending until the buffer is filled.

Authored by Claude Code.

Fixes darktable-org#21513
The preview pipe writes buf_width/buf_height under gui_lock on its
worker thread; the check in the GTK-side callback read them unlocked.

Authored by Claude Code.
@kofa73
kofa73 force-pushed the fix/ashift-lost-deferred-autocrop branch from 4be5df5 to 5e98e3e Compare September 19, 2026 14:08

@TurboGit TurboGit left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@TurboGit
TurboGit merged commit 3e94904 into darktable-org:master Sep 19, 2026
6 checks passed
@kofa73
kofa73 deleted the fix/ashift-lost-deferred-autocrop branch September 19, 2026 14:35
kofa73 added a commit to kofa73/darktable that referenced this pull request Sep 29, 2026
…geometry()

The buffer-size check that darktable-org#22332 added to the preview callback takes
gui_lock itself to read buf_width and buf_height. Use the snapshot
helper that the other GTK-side readers of the buffer geometry use, so
those fields are read in one place. No change in behavior.

Related: darktable-org#21918
kofa73 added a commit to kofa73/darktable that referenced this pull request Sep 29, 2026
The buffer-size check that darktable-org#22332 added to the preview callback takes
gui_lock itself to read buf_width and buf_height. Use the snapshot
helper that the other GTK-side readers of the buffer geometry use, so
those fields are read in one place. No change in behavior.

Related: darktable-org#21918
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:generated bugfix pull request fixing a bug scope: image processing correcting pixels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rotate sometimes forgets to re-scale to largest area

5 participants