Bug 420338 - [selection] Krita can't paint (empty selection, feedback issue)
Summary: [selection] Krita can't paint (empty selection, feedback issue)
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: Tools/Selection (show other bugs)
Version: 4.2.9
Platform: Other Linux
: NOR major
Target Milestone: ---
Assignee: wolthera
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-04-20 13:01 UTC by David REVOY
Modified: 2020-05-02 13:15 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Marching ants selection (19.34 KB, image/png)
2020-04-21 08:36 UTC, Ahab Greybeard
Details
Global Selection Mask selection (17.72 KB, image/png)
2020-04-21 08:37 UTC, Ahab Greybeard
Details

Note You need to log in before you can comment on or make changes to this bug.
Description David REVOY 2020-04-20 13:01:02 UTC
Hey, 

After visiting forums, blaming Windows driver of its XP-Pen tablet, checking the property of all layers, a user sent me this morning a Krita document that he couldn't paint on it anymore. Not possible to paint on any layers. The solution was simple but not obvious. And this bug could be a good prank to a co-worker using Krita 4.2.9. :D

To reproduce: 
=============
- Open a new multilayered document.
- Ctrl+A: Select all (notice the marching ant all around the canvas)
- Ctrl+Shift+i: Invert selection... (Tadaaaa! Marching ants disapear totally)
- Save now the document as *.kra, close it, reopen it, share it.

Result:
=======
It produce a invisble empty selection. So no feedback about the presence of selection: the canvas appears totally normal, no marching ant. Exept you can't paint on this document anymore nor apply filters. And this affect all layers. Workaround: Menu → Select → Deselect all  (nothing visually happens, but it unlock all). The user who sent this to me thought his artwork was just frozen this way.

Expected:
=========
If possible, a marching ant path around the canvas, even after inverting the selection.
Comment 1 Ahab Greybeard 2020-04-21 08:36:01 UTC
Created attachment 127733 [details]
Marching ants selection

I can confirm this for the 4.2.9 appimage and a recent 5.0.0 prealpha appimage.

It also happens with a single layer image.

If you make a selection on the canvas and then invert it, the marching ants are shown around the canvas border.
There seems to be a problem with selection boundaries that are on the edge of the canvas:
If you make an on canvas selection and invert it, then use the Move tool, the resulting marching ants display is as expected but then it does not correspond to the global selection mask.
The attached files Ants-A.png and GSM-A.png show an example of this.

Setting to Confirmed
Comment 2 Ahab Greybeard 2020-04-21 08:37:02 UTC
Created attachment 127734 [details]
Global Selection Mask selection
Comment 3 wolthera 2020-04-21 12:57:42 UTC
This bug seems to be at core here:

template <class StorageStrategy>
QVector<QPolygon> KisOutlineGenerator::outlineImpl(typename StorageStrategy::StorageType buffer, qint32 xOffset, qint32 yOffset, qint32 width, qint32 height)

It generates no paths under these conditions.
Comment 4 wolthera 2020-04-21 14:30:35 UTC
further discussion is here: https://invent.kde.org/kde/krita/-/merge_requests/309
Comment 5 wolthera 2020-04-23 10:08:23 UTC
copy-pasting the gist of an irc discussion on a technical solution here:

three ways to solve that: very hackish, a bit hackish and normal one

first one is just to skip adding selection in KisResourcesSnapshot if it is empty. But GUI will be still inconsistent and tools that don't use resources snapshot will still be locked

second one: add a custom code to KisSelectionDecoration::selectionChanged() that checks if the selection is empty and adds **a separate undo history step** that deselects the selection, when it is empty, that would break a few coding standards, but would somehow work

and the last one: extract the code from KisSelectionToolHelper::selectPixelSelection() that deselects the selection into something reusable and add that to all the selection modification actions the list of actions is not very long, btw

- so, I would like to do the last one, but how should I do that with selection-filters? Because the initial report was about the invert filter. And I think it might be quite possible to do with the other selection filters given a little creativity.

KisSelectionToolHelper::selectPixelSelection, KisSelectionToolHelper::addSelectionShapes, KisFilterSelectionOperation::runFilter

there is a base class, KisFilterSelectionOperation is the base class for all of them. Just add a CompositeCommand to it, like it happens in KisSelectionToolHelper::selectPixelSelection
so, ideally, it would be nice to extend the deselection code from KisSelectionToolHelper::selectPixelSelection() to work with local selections as well

ah, it is much easier, sorry. You should just use KisDeselectActiveSelectionCommand instead of KisDeselectGlobalSelectionCommand. and this command will choose the proper algorithm automagically

--------
(needless to say, we're going with the latter)
Comment 6 wolthera 2020-04-23 13:58:56 UTC
Git commit 607122920de6885a543421ad7a334e70f24aca10 by Wolthera van Hövell tot Westerflier.
Committed on 23/04/2020 at 13:58.
Pushed by woltherav into branch 'master'.

Ensure that selection masks get unactivated if the selection was emptied.

This can happen with selectall and then invert, or selecting an area and then deselecting
it fully, which ended up with an empty but active selection, and thus an inability to paint
on the drawing.

Global selection mask will be removed, local selection masks disabled, and in either case
the artist can go back to painting.

M  +11   -1    libs/ui/operations/kis_filter_selection_operation.cpp
M  +8    -2    libs/ui/tool/kis_selection_tool_helper.cpp

https://invent.kde.org/kde/krita/commit/607122920de6885a543421ad7a334e70f24aca10
Comment 7 Tiar 2020-05-02 13:15:41 UTC
Git commit 692225a9c4006460802d414a357c27922341d79e by Agata Cacko, on behalf of Wolthera van Hövell tot Westerflier.
Committed on 02/05/2020 at 13:15.
Pushed by tymond into branch 'krita/4.3'.

Ensure that selection masks get unactivated if the selection was emptied.

This can happen with selectall and then invert, or selecting an area and then deselecting
it fully, which ended up with an empty but active selection, and thus an inability to paint
on the drawing.

Global selection mask will be removed, local selection masks disabled, and in either case
the artist can go back to painting.

M  +11   -1    libs/ui/operations/kis_filter_selection_operation.cpp
M  +8    -2    libs/ui/tool/kis_selection_tool_helper.cpp

https://invent.kde.org/kde/krita/commit/692225a9c4006460802d414a357c27922341d79e