Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access Violation code when deleting a node with a widget on it and closing the application #444

Open
laurapons opened this issue Jan 27, 2025 · 1 comment

Comments

@laurapons
Copy link

If I create a node with a widget on it (for example a combobox), delete the node and close the application, the code breaks with and access violation return code.
Run the snippet below:

import sys
from PySide2.QtWidgets import QApplication
from NodeGraphQt import BaseNode, NodeGraph


class CustomNode(BaseNode):
    __identifier__ = 'com.example'
    NODE_NAME = 'Custom Node'

    # region Constructor

    def __init__(self):
        super(CustomNode, self).__init__()
        self.add_input('Input')
        self.add_output('Output')
        self.add_combo_menu(name='DROPDOWN_ID', items=[], tooltip='tooltip')
        self._combobox = self.widgets()['DROPDOWN_ID'].get_custom_widget()


app = QApplication([])

# Create a graph
graph = NodeGraph()

# Add delete command to the context menu
context_menu = graph.get_context_menu('graph')
context_menu.add_command('&Delete', lambda: graph.delete_nodes(graph.selected_nodes()), 'QtGui.QKeySequence.Delete')

# Register the custom node
graph.register_node(CustomNode)
# Create an instance of the custom node and add it to the graph
graph.create_node('com.example.CustomNode', name=CustomNode.NODE_NAME)
# Create a window to display the graph
graph_widget = graph.widget
graph_widget.show()

# Start the application
sys.exit(app.exec_())

The error I get is:

Process finished with exit code -1073741819 (0xC0000005)

I use:
PySide2 5.15.2.1
NodeGraphQt 0.6.38

I tried debugging the dump file, but I could not find any trace of why it crashes (probably not deleting the Qt widgets properly?). I need help on this, I cannot use the application without being able to add any widget on the node and not crashing.

@laurapons
Copy link
Author

laurapons commented Jan 27, 2025

While trying to debug this error I found out that if you force C++ to delete the item after being removed from the scene, it does not crash anymore (idea taken from https://stackoverflow.com/questions/63205311/how-to-delete-a-qgraphicsitem-in-pyqt5).
So I put:
shiboken2.delete(item_to_be_deleted) everywhere int the code where removeItem is called, and it doesn't break anymore.

(note aside, I use the pyside6 code from the open PR so I initially tested the fixing with shiboken6 and then retest it with shiboken2 to make sure it was working with the latest version).

Changes apply to these files:
Image

Example from the node_abstract file:

Image

It would be really nice if you can put that fixing in the next release, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant