Skip to content
Snippets Groups Projects

Don't build .kra file if image is empty

Merged Lucid Sunlight requested to merge awakening/krita:bug-429049 into master
All threads resolved!

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?

BUG:429049

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

Merged by Dmitry KazakovDmitry Kazakov 3 years ago (Dec 19, 2020 9:53am UTC)

Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • 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 :)

  • Dmitry Kazakov added Needs Changes label and removed Needs Review label

    added Needs Changes label and removed Needs Review label

  • Lucid Sunlight added 48 commits

    added 48 commits

    Compare with previous version

  • Dmitry Kazakov added Approved label and removed Needs Changes label

    added Approved label and removed Needs Changes label

  • Dmitry Kazakov resolved all threads

    resolved all threads

  • Please register or sign in to reply
    Loading