hoffstadt / DearPyGui

Dear PyGui: A fast and powerful Graphical User Interface Toolkit for Python with minimal dependencies
https://dearpygui.readthedocs.io/en
MIT License
13.04k stars 677 forks source link

Binding a handler to node_link leads to a segfault #2197

Closed v-ein closed 9 months ago

v-ein commented 1 year ago

Version of Dear PyGui

Version: 1.9.1 Operating System: Windows 10

My Issue/Question

Whenever a handler is bound to node_link, DPG segfaults. See also #2196 for details on handler applicability.

Note: the only handler supported by a node link is item_hover_handler, which cannot be bound until #2196 is fixed. That is, this issue cannot be tested until #2196 is fixed.

To Reproduce

Steps to reproduce the behavior:

  1. Run the example below.
  2. It segfaults right away.

Expected behavior

When a supported handler is bound to node_link (see also #2196), there must be no segfaults, and the handler must run whenever there are appropriate conditions for that.

Screenshots/Video

None.

Standalone, minimal, complete and verifiable example

import traceback
import dearpygui.dearpygui as dpg

dpg.create_context()
with dpg.window(label="Example Window") as main:
    with dpg.node_editor() as editor:
        with dpg.node(label="Node 1", pos=(20, 20)):
            with dpg.node_attribute(label="Attr", attribute_type=dpg.mvNode_Attr_Output) as attr1:
                dpg.add_text("Text")

        with dpg.node(label="Node 2", pos=(220, 20)):
            with dpg.node_attribute(label="Attr", attribute_type=dpg.mvNode_Attr_Input) as attr2:
                dpg.add_text("Text")

        node_link = dpg.add_node_link(attr1, attr2, parent=editor)

        try:
            with dpg.item_handler_registry() as handlers:
                dpg.add_item_hover_handler(callback=lambda: print("Node link hovered"))
            dpg.bind_item_handler_registry(node_link, handlers)
        except Exception as e:
            print("Failed to bind - please make sure #2196 has been fixed.")
            print(traceback.format_exc())

dpg.create_viewport()
dpg.setup_dearpygui()

dpg.set_primary_window(main, True)

dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
v-ein commented 1 year ago

Caused by a null pointer. Got a fix for it and going to eventually open a PR.