• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Painter crashes on startup - python plugin delete_ui_element

Community Beginner ,
Sep 21, 2021 Sep 21, 2021

Copy link to clipboard

Copied

Hello,

I'm writing a Python plugin for Substance Painter and I discover a bug that creates crash on startup:

I have a virtualenv containing these versions:

PySide2==5.12.5
Qt.py==1.3.3
shiboken2==5.12.5

 
I add virtualenv's site-packages to my PYTHONPATH and launch Painter with this script inside startup folder :

 

from Qt import QtWidgets
import substance_painter


PLUGIN_WIDGETS = []


def display_dialog():
    main_window = substance_painter.ui.get_main_window()
    dialog = QtWidgets.QDialog(main_window)
    dialog.show()


def start_plugin():
    global PLUGIN_WIDGETS
    menu = QtWidgets.QMenu("&Test Menu")
    action = unit_menu.addAction("Test")
    action.triggered.connect(display_dialog)
    substance_painter.ui.add_menu(menu)
    PLUGIN_WIDGETS.append(menu)


def close_plugin():
    global PLUGIN_WIDGETS
    for widget in PLUGIN_WIDGETS:
        substance_painter.ui.delete_ui_element(widget)
    PLUGIN_WIDGETS = []

 


I just add a menu "Test" with a "test" action inside and the action open an empty dialog linked to Painter's main window.

When I click on the action to display the dialog, the dialog is correctly shown. But, if I restart Painter just after, I have a crash on startup without message on log files and Painter starts on "Report" window's close.

To fix it, I append my dialog to "PLUGIN_WIDGETS" to delete it on plugin close. It works for this small plugin, but I can't do it for all widgets created in bigger plugins (I will add more complicated Python scripts used also in other software).


Is there another way to prevent this startup crash? Is this bug normal?

Thanks in advance!
Coralie Goldbaum.

TOPICS
Bugs & Crashes , Scripting

Views

239

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 21, 2021 Sep 21, 2021

Copy link to clipboard

Copied

Edit: I have the same error without my virtualenv with Qt.py and using directly PySide2.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 21, 2021 Sep 21, 2021

Copy link to clipboard

Copied

More information:

Version 7.1.1 (but also tested on version 7.2) and platform Windows 10 64bits.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 18, 2021 Oct 18, 2021

Copy link to clipboard

Copied

Hello,

We also have this crash when we parent a QWidget to Substance Painter MainWindow:

"""
                    
Parenting a QWidget to the substance main window makes the next Painter instance to raise an error
"""
import substance_painter
from PySide2 import QtWidgets
PLUGIN_WIDGETS = []
def display_dialog():
    main_window = substance_painter.ui.get_main_window()
    dialog = QtWidgets.QDialog(parent=main_window)  # Here
    dialog.exec_()
def start_plugin():
    global PLUGIN_WIDGETS
    menu = QtWidgets.QMenu("&Test Menu")
    action = menu.addAction("Test")
    action.triggered.connect(display_dialog)
    substance_painter.ui.add_menu(menu)
    PLUGIN_WIDGETS.append(menu)
def close_plugin():
    global PLUGIN_WIDGETS
    for widget in PLUGIN_WIDGETS:
        substance_painter.ui.delete_ui_element(widget)
    PLUGIN_WIDGETS = None
if __name__ == "__main__":
    start_plugin()

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 28, 2022 Sep 28, 2022

Copy link to clipboard

Copied

I am also suffering from the same phenomenon.
Has it been resolved?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 10, 2022 Oct 10, 2022

Copy link to clipboard

Copied

I am experiencing this as well. What is the suggested solution? Thanks!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 10, 2022 Oct 10, 2022

Copy link to clipboard

Copied

LATEST

We've spent more time looking into this and found that adding the following line resolves the issue:
dialog.setAttribute(QtGui.Qt.WA_DeleteOnClose)

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources