PasteIntoAction: Preserve shared pointer as a variable
I discovered a bug while attempting to paste a selection of one JPEG image into the active layer of another JPEG image. Krita would crash when it tried calling defaultBounds->externalFrameActive()
in the function currentNonLodData()
While defaultBounds
itself was not null, the data it had been referencing was getting prematurely destroyed, and it showed that it had a reference count of zero.
This was happening because we were creating a local variable for a (const KisPaintDevice *
), while immediately discarding the shared pointer from whence it came. If we instead make it so that the shared pointer is the local variable, its data is guaranteed to remain in scope long enough to make use of it.
Test Plan
- In Krita, open a JPEG image.
- With the selection tool, select a portion of the JPEG image and click
Edit -> Copy
. - Open a second JPEG image.
- With Krita focused on the second JPEG image, click
Edit -> Paste into Active Layer
.
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.