Don't build .kra file if image is empty
Happens when drag&dropping empty layers.
Can cause modulo by zero crash in KisDocument::generatePreview
when dragging onto canvas, or somewhere in QuaZip when dragging outside of Krita.
Also avoid showing a warning window when you drop empty layer onto canvas by avoiding hitting deserialization in application/x-krita-node
and
application/x-krita-node-url
branches in KisMimeData::loadNodesKisMimeData::loadNodes
(still adds a new empty layer).
Not too happy about this, as it now adds an assumption that x-krita-node
and x-krita-node-url
are the same node. Is there an edge case where they're not?
Test Plan
- Create/open a document
- Create an empty layer
- Drag&drop it onto canvas
- Don't crash
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
Activity
added Needs Review label
assigned to @dkazakov
- Resolved by Dmitry Kazakov
- Resolved by Dmitry Kazakov
- Resolved by Dmitry Kazakov
Hi, @awakening!
I'm not really sure why these checks for the bytearray's size are needed. It looks like the original bug can be fixed with this trivial patch.
diff --git a/libs/ui/kis_mimedata.cpp b/libs/ui/kis_mimedata.cpp index 8bbb0bff537..8f8f536bba1 100644 --- a/libs/ui/kis_mimedata.cpp +++ b/libs/ui/kis_mimedata.cpp @@ -87,6 +87,10 @@ KisDocument *createDocument(QList<KisNodeSP> nodes, KisImageSP srcImage) rc |= node->exactBounds(); } + if (rc.isEmpty()) { + rc = srcImage->bounds(); + } + KisImageSP image = new KisImage(0, rc.width(), rc.height(), nodes.first()->colorSpace(), nodes.first()->name()); image->setAllowMasksOnRootNode(true);
Can you check if this small patch fixes the original problem? If yes, I'd prefer this fix to using this suspicious
validKritaNode
:)
added Needs Changes label and removed Needs Review label
added 48 commits
-
6653b7da...d3d84d35 - 45 commits from branch
graphics:master
- 11a8010d - Don't build .kra file if image is empty
- 7bb4f7f5 - Parse URL once
- f55654f8 - Default to image bounds if nodes are empty
Toggle commit list-
6653b7da...d3d84d35 - 45 commits from branch
added Approved label and removed Needs Changes label