Bug 461555 - Trying to set a pattern through Krita API generate a crash
Summary: Trying to set a pattern through Krita API generate a crash
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: Scripting (other bugs)
Version First Reported In: 5.1.0
Platform: Other Linux
: NOR crash
Target Milestone: ---
Assignee: Krita Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-11-07 17:22 UTC by grum999
Modified: 2023-01-12 22:11 UTC (History)
3 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description grum999 2022-11-07 17:22:02 UTC
SUMMARY
Trying to set a pattern through Krita API generate a crash

STEPS TO REPRODUCE
In scripter, execute following script:
```
import krita

allPatterns = Krita.instance().resources('pattern')
pattern = allPatterns["DITH 0404 CLUS"]
    
av=Krita.instance().activeWindow().activeView()
av.setCurrentPattern(pattern)  
```

OBSERVED RESULT
Krita 5.1.0: crash (segmentation fault)
Krita 4.4.8: defined pattern is selected properly (no crash)

EXPECTED RESULT
Krita do not crash and defined pattern is selected
Comment 1 wolthera 2023-01-12 12:56:27 UTC
I can confirm this, but my local build doesn't have python, so I can't get a backtrace.
Comment 2 Freya Lupen 2023-01-12 13:51:03 UTC
The backtrace looks like this; a similar crash also happens when attempting to set a gradient.
> * thread #1, stop reason = Exception 0xc0000005 encountered at address 0x7ffb263bf888: Access violation reading location 0x00000008
>   * frame #0: 0x00007ffb263bf888 libkritaresources.dll`KoResource::image(this=0x0000000000000000) const at KoResource.cpp:123:12
>     frame #1: 0x00007ffb305e5ad4 libkritaui.dll`KisControlFrame::slotSetPattern(this=0x0000023cc4f27330, pattern=KoPatternSP @ 0x000000f18830a630) at kis_control_frame.cpp:142:44
>     frame #2: 0x00007ffb30486742 libkritaui.dll`KisControlFrame::qt_static_metacall(_o=<unavailable>, _c=<unavailable>, _id=<unavailable>, _a=<unavailable>) at moc_kis_control_frame.cpp:85:21
>     frame #3: 0x00007ffb1edb8efd Qt5Core.dll`void doActivate<false>(QObject*, int, void**) at qobject.cpp:3931:21
>     frame #4: 0x00007ffb30485c3a libkritaui.dll`KisCanvasResourceProvider::sigPatternChanged(this=<unavailable>, _t1=<unavailable>) at moc_kis_canvas_resource_provider.cpp:506:5
>     frame #5: 0x00007ffb305c79c2 libkritaui.dll`KisCanvasResourceProvider::slotCanvasResourceChanged(this=0x0000023cc4f274d0, key=<unavailable>, res=<unavailable>) at kis_canvas_resource_provider.cpp:304:14
>     frame #6: 0x00007ffb1edb8efd Qt5Core.dll`void doActivate<false>(QObject*, int, void**) at qobject.cpp:3931:21
>     frame #7: 0x00007ffb126d1de5 libkritaflake.dll`KoCanvasResourceProvider::canvasResourceChanged(this=<unavailable>, _t1=6002, _t2=<unavailable>) at moc_KoCanvasResourceProvider.cpp:170:5
>     frame #8: 0x00007ffb1edb8dd2 Qt5Core.dll`void doActivate<false>(QObject*, int, void**) [inlined] QtPrivate::QSlotObjectBase::call(QObject*, void**) at qobjectdefs_impl.h:398:51
>     frame #9: 0x00007ffb1edb8db3 Qt5Core.dll`void doActivate<false>(QObject*, int, void**) at qobject.cpp:3919:26
>     frame #10: 0x00007ffb126d2485 libkritaflake.dll`KoResourceManager::resourceChanged(this=<unavailable>, _t1=6002, _t2=<unavailable>) at moc_KoResourceManager_p.cpp:154:5
>     frame #11: 0x00007ffb126d850b libkritaflake.dll`KoResourceManager::setResource(int, QVariant const&) [inlined] KoResourceManager::notifyResourceChanged(this=0x0000023cbda06d60, key=6002, value=0x000000f18830abf0) at KoResourceManager_p.cpp:69:10
>     frame #12: 0x00007ffb126d84fe libkritaflake.dll`KoResourceManager::setResource(this=0x0000023cbda06d60, key=6002, value=0x000000f18830abf0) at KoResourceManager_p.cpp:56:13
>     frame #13: 0x00007ffadce4da3d libkritalibkis.dll`View::activateResource(this=0x0000023c87065840, resource=<unavailable>) at View.cpp:120:51
>     frame #14: 0x00007ffadcb55cf1 krita.pyd`meth_View_setCurrentPattern(sipSelf=0x0000023c88ee54c0, sipArgs=<unavailable>) at sipkritapart0.cpp:28435:21

In other words, there's no image here:
kis_control_frame.cpp:142:     m_patternWidget->setThumbnail(pattern->image());
Comment 3 amyspark 2023-01-12 18:54:01 UTC
However, upon reproducing the traceback, the pattern is not null; it becomes null somewhere between View::activateResource and KisControlFrame::slotSetPattern. Assigning to myself.
Comment 4 amyspark 2023-01-12 22:10:58 UTC
Git commit 33f242b8875ef305541bd6536f17500906ea5cc4 by L. E. Segovia.
Committed on 12/01/2023 at 22:10.
Pushed by lsegovia into branch 'master'.

libkis: Use the proper pointer types for marshalling resources on activation

M  +8    -13   libs/libkis/View.cpp
M  +5    -2    libs/ui/kis_control_frame.cpp
M  +1    -2    plugins/dockers/patterndocker/patterndocker_dock.cpp

https://invent.kde.org/graphics/krita/commit/33f242b8875ef305541bd6536f17500906ea5cc4
Comment 5 amyspark 2023-01-12 22:11:50 UTC
Git commit 9015a38695f16639170b349962d16c6328f126a5 by L. E. Segovia.
Committed on 12/01/2023 at 22:11.
Pushed by lsegovia into branch 'krita/5.1'.

libkis: Use the proper pointer types for marshalling resources on activation
(cherry picked from commit 33f242b8875ef305541bd6536f17500906ea5cc4)

M  +8    -13   libs/libkis/View.cpp
M  +5    -2    libs/ui/kis_control_frame.cpp
M  +1    -2    plugins/dockers/patterndocker/patterndocker_dock.cpp

https://invent.kde.org/graphics/krita/commit/9015a38695f16639170b349962d16c6328f126a5