Skip to content

Fix issue when closing a document while some selection tools are selecting

This MR fixes some crashes that happened when the document was closed while a selection rectangular/elliptical or freehand selection was still being made.

The issue seems to happen because the canvas loses focus when closing the document, for example with ctrl+w, and after a chain of method calls the endPrimaryAction is called on the tool. When in vector mode this means that a shape was to be added to the selection, apparently in a asynchronously fashion. But it seems that when this happens the image was already destroyed (or something like that, I didn't check in depth).

Instead of dealing with that asynch issue, this MR tries to make the tools themselves more robust, in a way that the shape is not added in the first place if not needed. For that I introduced a check to see if the event in endPrimaryAction is spontaneous (the user actually released the mouse button). In that case, the shape is ended and added. But if the event is not spontaneous, then the shape is cancelled. In other words, if the endPrimaryAction is called because of user interaction, then the action is completed and the shape is added. If not (the canvas lost focus, for example), then the action is cancelled and the shape is not added. I also reimplemented requestStrokeEnd and requestStrokeCancellation on those tools to make them more robust.

I think that this solution ensures that the KisToolRectangleBase and KisToolOutlineBase can be used safer in more situations.

Formalities Checklist

  • I confirmed this builds.
  • I confirmed Krita ran and the relevant functions work.
  • I tested the relevant unit tests and can confirm they are not broken. (If not possible, don't hesitate to ask for help!)
  • I made sure my commits build individually and have good descriptions as per KDE guidelines.
  • I made sure my code conforms to the standards set in the HACKING file.
  • I can confirm the code is licensed and attributed appropriately, and that unattributed code is mine, as per KDE Licensing Policy.

Merge request reports