Bug 518235 - Krita 5.3 Invert Selection exceeds canvas
Summary: Krita 5.3 Invert Selection exceeds canvas
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: Tools/Selection (other bugs)
Version First Reported In: 5.3.0
Platform: Microsoft Windows Microsoft Windows
: NOR normal
Target Milestone: ---
Assignee: ricky.ringler
URL:
Keywords:
: 518940 519757 (view as bug list)
Depends on:
Blocks:
 
Reported: 2026-03-27 19:55 UTC by Missy
Modified: 2026-06-15 09:09 UTC (History)
8 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Missy 2026-03-27 19:55:48 UTC
SUMMARY
I often use 'invert selection' to grow and create a cut line for files sent off to be made into stickers or other printouts in Krita. After updating to Krita 3.0, the 'invert selection' includes a strange selection in the bottom and right portions off canvas consistently with all my files, whether transparent .png files or cropping and selecting with a new blank .kra file.

STEPS TO REPRODUCE
1. Create new file, color a blob anywhere. Crop to desired size, save as a png (this is showing up with jpg as well now though not as dramatically).
2. Close document, reopen flattened file (jpg or png), and use the selection tool to select around the color blob. Choose invert.
3. Selection inverts but adds a selection around the right and/or bottom outside of canvas.

OBSERVED RESULT
https://krita-artists.org/t/krita-5-3-selection-update-issue/177356
https://youtu.be/w1SMdWeHnxQ

EXPECTED RESULT
Expected result is to not include outside the canvas.

SOFTWARE/OS VERSIONS
Windows: 10
Comment 1 Ahab Greybeard 2026-03-27 20:19:03 UTC
I can confirm this for the 5.3.0 appimage running on Linux Mint.

It happens with any .png file, not just one made by Exporting from krita but the contents have an effect.
If there is an isolated blob on a transparent background then inverting a selection shows the problem.
If there are two or more blobs on a transparent background then there is no problem.

Also, modifying the image by erasing outside of the canvas will increase the selected area that is added by inverting a selection.

These observations do not happen with a new document made in krita, only with an imported .png/.jpg file.
Comment 2 dra.w.p.il.e+bugskde 2026-05-04 14:04:57 UTC
*** Bug 518940 has been marked as a duplicate of this bug. ***
Comment 3 dra.w.p.il.e+bugskde 2026-05-04 14:05:14 UTC
*** Bug 519757 has been marked as a duplicate of this bug. ***
Comment 4 eishiya 2026-05-17 00:23:26 UTC
This can happen with any document no matter how it was created. The number of blobs/marks or how they were does not matter as far as I can tell, only the location of the non-transparent pixels does. Pixels close to the bottom and right edges cause this, as do pixels anywhere off-canvas.

I'm guessing Krita allocates data in chunks rather than pixel by pixel or for the entire layer, and when there are marks near the bottom/right canvas edge or off the canvas to the top/left, it allocates chunks that partially go off-canvas, and those off-canvas empty pixels are erroneously included when inverting the selection. I experimented with various canvas sizes, and it seems the extra pixels "added" in the inverted selection always pad the effective size to some multiple of a power of 2. On a 64x64 canvas, the bug does not occur unless pixels are placed off-canvas, I'm guessing because the allocated chunks exactly match the canvas size. (The chunk size seems to grow with the canvas size though, so just making the canvas a multiple of 64x64 is not enough to avoid this bug, it's likely there are only a few "perfect" canvas sizes.)

(I'm on 5.3.1)
Comment 5 ricky.ringler 2026-05-17 02:05:21 UTC
I can reproduce on Arch Linux on KDE with the Krita development branch.

We're not handling well, where the selection size exceeds the canvas size. See commit d361e80ffa4676619a242ac3b53b27bd1ec89761 on invent.

It seems like we're iterating incorrectly over the canvas, which leaves these "gaps" in the +X/-Y space.

I will open an MR if I have time.
Comment 6 Tiar 2026-05-28 15:21:09 UTC
I set you as an assignee, then. Thanks!
Comment 7 ricky.ringler 2026-05-28 17:41:31 UTC
(In reply to Tiar from comment #6)
> I set you as an assignee, then. Thanks!

FYI I have a patch open to resolve. Pending approval to merge to the dev branch.

Thank you.