Bug 441838 - Ten Brushes crashes: wrapped C/C++ object of type QWidgetAction has been deleted
Summary: Ten Brushes crashes: wrapped C/C++ object of type QWidgetAction has been deleted
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: Scripting (show other bugs)
Version: 5.0.0-beta1
Platform: Microsoft Windows Microsoft Windows
: NOR crash
Target Milestone: ---
Assignee: Dmitry Kazakov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-09-01 01:07 UTC by Yu-Hsuan Lai
Modified: 2023-07-14 11:39 UTC (History)
2 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 Yu-Hsuan Lai 2021-09-01 01:07:36 UTC
SUMMARY
Ten Brushes script crashes itself

STEPS TO REPRODUCE
1. Tools -> Scripts -> Ten Brushes

OBSERVED RESULT
The script (not the whole Krita) crashes with the following log:

----
RuntimeError
Python 3.8.1: C:\Program Files\Krita (x64)\bin\krita.exe
Wed Sep  1 09:06:55 2021

A problem occurred in a Python script.  Here is the sequence of
function calls leading up to the error, in the order they occurred.

 C:\Program Files\Krita (x64)\share\krita\pykrita\tenscripts\tenscripts.py in initialize(self=<tenscripts.tenscripts.TenScriptsExtension object>)
   31     def initialize(self):
   32         self.uitenscripts = uitenscripts.UITenScripts()
   33         self.uitenscripts.initialize(self)
   34 
   35     def readSettings(self):
self = <tenscripts.tenscripts.TenScriptsExtension object>
self.uitenscripts = <tenscripts.uitenscripts.UITenScripts object>
self.uitenscripts.initialize = <bound method UITenScripts.initialize of <tenscripts.uitenscripts.UITenScripts object>>

 C:\Program Files\Krita (x64)\share\krita\pykrita\tenscripts\uitenscripts.py in initialize(self=<tenscripts.uitenscripts.UITenScripts object>, tenscripts=<tenscripts.tenscripts.TenScriptsExtension object>)
   35         self.tenscripts = tenscripts
   36 
   37         self._loadGridLayout()
   38         self._fillScripts()
   39 
self = <tenscripts.uitenscripts.UITenScripts object>
self._loadGridLayout = <bound method UITenScripts._loadGridLayout of <tenscripts.uitenscripts.UITenScripts object>>

 C:\Program Files\Krita (x64)\share\krita\pykrita\tenscripts\uitenscripts.py in _loadGridLayout(self=<tenscripts.uitenscripts.UITenScripts object>)
   97     def _loadGridLayout(self):
   98         for item in range(0, 10):
   99             self.addNewRow(item)
  100 
  101     def _fillScripts(self):
self = <tenscripts.uitenscripts.UITenScripts object>
self.addNewRow = <bound method UITenScripts.addNewRow of <tenscripts.uitenscripts.UITenScripts object>>
item = 0

 C:\Program Files\Krita (x64)\share\krita\pykrita\tenscripts\uitenscripts.py in addNewRow(self=<tenscripts.uitenscripts.UITenScripts object>, key=0)
   60 
   61         directoryTextField.setReadOnly(True)
   62         label.setText(self.tenscripts.actions[key].shortcut().toString(QKeySequence.NativeText))
   63         directoryTextField.setToolTip(i18n("Selected path"))
   64         directoryDialogButton.setToolTip(i18n("Select the script"))
label = <PyQt5.QtWidgets.QLabel object>
label.setText = <built-in method setText of QLabel object>
self = <tenscripts.uitenscripts.UITenScripts object>
self.tenscripts = <tenscripts.tenscripts.TenScriptsExtension object>
self.tenscripts.actions = [<PyQt5.QtWidgets.QWidgetAction object>, <PyQt5.QtWidgets.QWidgetAction object>, <PyQt5.QtWidgets.QWidgetAction object>, <PyQt5.QtWidgets.QWidgetAction object>, <PyQt5.QtWidgets.QWidgetAction object>, <PyQt5.QtWidgets.QWidgetAction object>, <PyQt5.QtWidgets.QWidgetAction object>, <PyQt5.QtWidgets.QWidgetAction object>, <PyQt5.QtWidgets.QWidgetAction object>, <PyQt5.QtWidgets.QWidgetAction object>, <PyQt5.QtWidgets.QWidgetAction object>, <PyQt5.QtWidgets.QWidgetAction object>, <PyQt5.QtWidgets.QWidgetAction object>, <PyQt5.QtWidgets.QWidgetAction object>, <PyQt5.QtWidgets.QWidgetAction object>, <PyQt5.QtWidgets.QWidgetAction object>, <PyQt5.QtWidgets.QWidgetAction object>, <PyQt5.QtWidgets.QWidgetAction object>, <PyQt5.QtWidgets.QWidgetAction object>, <PyQt5.QtWidgets.QWidgetAction object>, ...]
key = 0
].shortcut undefined
global QKeySequence = <class 'PyQt5.QtGui.QKeySequence'>
QKeySequence.NativeText = 0
RuntimeError: wrapped C/C++ object of type QWidgetAction has been deleted
    __cause__ = None
    __class__ = <class 'RuntimeError'>
    __context__ = None
    __delattr__ = <method-wrapper '__delattr__' of RuntimeError object>
    __dict__ = {}
    __dir__ = <built-in method __dir__ of RuntimeError object>
    __doc__ = 'Unspecified run-time error.'
    __eq__ = <method-wrapper '__eq__' of RuntimeError object>
    __format__ = <built-in method __format__ of RuntimeError object>
    __ge__ = <method-wrapper '__ge__' of RuntimeError object>
    __getattribute__ = <method-wrapper '__getattribute__' of RuntimeError object>
    __gt__ = <method-wrapper '__gt__' of RuntimeError object>
    __hash__ = <method-wrapper '__hash__' of RuntimeError object>
    __init__ = <method-wrapper '__init__' of RuntimeError object>
    __init_subclass__ = <built-in method __init_subclass__ of type object>
    __le__ = <method-wrapper '__le__' of RuntimeError object>
    __lt__ = <method-wrapper '__lt__' of RuntimeError object>
    __ne__ = <method-wrapper '__ne__' of RuntimeError object>
    __new__ = <built-in method __new__ of type object>
    __reduce__ = <built-in method __reduce__ of RuntimeError object>
    __reduce_ex__ = <built-in method __reduce_ex__ of RuntimeError object>
    __repr__ = <method-wrapper '__repr__' of RuntimeError object>
    __setattr__ = <method-wrapper '__setattr__' of RuntimeError object>
    __setstate__ = <built-in method __setstate__ of RuntimeError object>
    __sizeof__ = <built-in method __sizeof__ of RuntimeError object>
    __str__ = <method-wrapper '__str__' of RuntimeError object>
    __subclasshook__ = <built-in method __subclasshook__ of type object>
    __suppress_context__ = False
    __traceback__ = <traceback object>
    args = ('wrapped C/C++ object of type QWidgetAction has been deleted',)
    with_traceback = <built-in method with_traceback of RuntimeError object>

The above is a description of an error in a Python program.  Here is
the original traceback:

Traceback (most recent call last):
  File "C:\Program Files\Krita (x64)\share\krita\pykrita\tenscripts\tenscripts.py", line 33, in initialize
    self.uitenscripts.initialize(self)
  File "C:\Program Files\Krita (x64)\share\krita\pykrita\tenscripts\uitenscripts.py", line 37, in initialize
    self._loadGridLayout()
  File "C:\Program Files\Krita (x64)\share\krita\pykrita\tenscripts\uitenscripts.py", line 99, in _loadGridLayout
    self.addNewRow(item)
  File "C:\Program Files\Krita (x64)\share\krita\pykrita\tenscripts\uitenscripts.py", line 62, in addNewRow
    label.setText(self.tenscripts.actions[key].shortcut().toString(QKeySequence.NativeText))
RuntimeError: wrapped C/C++ object of type QWidgetAction has been deleted
---

EXPECTED RESULT
Shows Ten Brushes' panel

SOFTWARE/OS VERSIONS
Krita

 Version: 5.0.0-beta1
 Languages: en_US, en
 Hidpi: true

Qt

  Version (compiled): 5.12.11
  Version (loaded): 5.12.11

OS Information

  Build ABI: x86_64-little_endian-llp64
  Build CPU: x86_64
  CPU: x86_64
  Kernel Type: winnt
  Kernel Version: 10.0.22000
  Pretty Productname: Windows 10 (10.0)
  Product Type: windows
  Product Version: 10


ADDITIONAL INFORMATION
Comment 1 Halla Rempt 2021-09-01 10:28:07 UTC
I'm sorry, but I cannot reproduce this issue. Did you build Krita yourself like you indicated in the Platform field originally? What language is your system set to?
Comment 2 Yu-Hsuan Lai 2021-09-01 13:20:39 UTC
(In reply to Halla Rempt from comment #1)
> I'm sorry, but I cannot reproduce this issue. Did you build Krita yourself
> like you indicated in the Platform field originally? What language is your
> system set to?

Uh no it's just official 5.0.0-beta1 build. My system is in English.

I observed something else... when I restart Krita, Ten Brushes works. But after a while it shows this error (but I can still use its shortcuts to switch brushes, just can't open the panel to set which slot is which brush).

And once it crashes, if I restart Krita it works again. Then after a while it crashes again. I haven't pinpointed which action causes it to start crashing.
Comment 3 Yu-Hsuan Lai 2021-09-01 13:28:10 UTC
Ok, I pinpointed it. On my computer these steps reproduce it 100% of the time.

1. Start Krita
2. Select Windows layout "Dual screen editing" (I believe it's built-in)
3. Tools -> Scripts -> Ten Brushes
Comment 4 Halla Rempt 2021-09-01 13:31:31 UTC
Yes! Thanks for figuring this out.
Comment 5 Dmitry Kazakov 2023-07-14 07:56:34 UTC
The bug is still reproducible in master :)
Comment 6 Dmitry Kazakov 2023-07-14 11:39:34 UTC
Git commit 5c1674f3e4a76bbb9b43ca08b3c42afa2c9e3007 by Dmitry Kazakov.
Committed on 14/07/2023 at 11:39.
Pushed by dkazakov into branch 'master'.

Fix Ten Brushes Plugin not to crash after closing the main window

Basically, python plugins should not store any pointers to actions,
since actions belong to a specific window, which may be destroyed
or switched.

The same issue was present in Ten Scripts plugin

M  +23   -21   plugins/python/tenbrushes/tenbrushes.py
M  +5    -3    plugins/python/tenbrushes/uitenbrushes.py
M  +8    -13   plugins/python/tenscripts/tenscripts.py
M  +6    -4    plugins/python/tenscripts/uitenscripts.py

https://invent.kde.org/graphics/krita/-/commit/5c1674f3e4a76bbb9b43ca08b3c42afa2c9e3007