Bug 487963 - kis_paint_device assert when altering layer from Python
Summary: kis_paint_device assert when altering layer from Python
Status: RESOLVED INTENTIONAL
Alias: None
Product: krita
Classification: Applications
Component: Scripting (show other bugs)
Version: nightly build (please specify the git hash!)
Platform: Microsoft Windows Microsoft Windows
: NOR crash
Target Milestone: ---
Assignee: Krita Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-06-03 14:22 UTC by IPv6
Modified: 2024-11-07 18:57 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
assert (226.08 KB, image/png)
2024-06-03 14:22 UTC, IPv6
Details

Note You need to log in before you can comment on or make changes to this bug.
Description IPv6 2024-06-03 14:22:25 UTC
Created attachment 170092 [details]
assert

SUMMARY

I have custom addon that replace layer byte data from python after custom processing. It worked well in Krita 5.2.+ and 5.3.0. Today i updated Krita Next to nightly build and it started to show an assert on each action. Tested both on MacOs and Windows - same assert on same action. It worked the same way well in previous nightly builds of 5.3.0

The python code that trigger assert is:
activeSel = doc.selection()
... many actions involving erode/dilate of selection ...
# restoring initial selection
doc.setSelection(activeSel) # causes assert

OBSERVED RESULT
- Assert in console SAFE ASSERT (krita): "!m_d->parent || !parent" in file /Users/gitlab/ws/builds/GZwHuM5x/0/graphics/krita/libs/image/kis_paint_device.cc, line 1195
- Alert on screen

EXPECTED RESULT
- no assert

SOFTWARE/OS VERSIONS
Windows: Windows 11
macOS: Sonoma 14.5 (23F79)
Comment 1 Halla Rempt 2024-07-27 09:14:12 UTC
Thank you for the report. Usually, safe asserts are not shown to the users, so they are not a huge deal. But I can confirm the issue.
Comment 2 Dmitry Kazakov 2024-11-07 18:57:57 UTC
Hi, IPv6!

When you modify the selection, you need to first duplicate the selection with `Selection::duplicate()` and then modify it:

```python
from krita import *
doc = Krita.instance().activeDocument()
activeSel = doc.selection()
newSel = activeSel.duplicate()
newSel.invert()
doc.setSelection(newSel)
```

Please take it into account that the selection should be a **raster** selection for this code to work correctly.