enthought / enable

Enable: low-level drawing and interaction
Other
91 stars 45 forks source link

RuntimeError: Internal C++ object (QResizableScrollBar) already deleted when running enable/enable/examples/demo/enable/scrolled_canvas_demo with python3.11 #1031

Open homosapien-lcy opened 1 year ago

homosapien-lcy commented 1 year ago

Problem Description Some examples involving enable/enable/qt4/scrollbar.py can be run successfully, but after closing, an already deleted error will arise.

Reproduction Steps:

python enable/enable/examples/demo/enable/scrolled_canvas_demo.py

Then close the plot window

Expected behavior: The window closed without error (the first part of the error message is related to issue #1030, not in the scope of the current issue)

(py311) (base) cyliu@aus552cyliu 3.11_test % python3.11 enable/enable/examples/demo/enable/scrolled_canvas_demo.py 
2023-04-17 12:58:47.542 Python[5395:129652] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to /var/folders/2z/kylzj9s92y71cxscmljmpqrh0000gt/T/org.python.python.savedState
Traceback (most recent call last):
  File "/Users/cyliu/Documents/3.11_test/enable/enable/examples/demo/enable/scrolled_canvas_demo.py", line 82, in <module>
    demo = demo_main(Demo, title="Canvas example")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cyliu/Documents/3.11_test/enable/enable/examples/_example_support.py", line 40, in demo_main
    demo_class().configure_traits()
  File "/Users/cyliu/Documents/3.11_test/traits/traits/has_traits.py", line 2163, in configure_traits
    rc = toolkit().view_application(
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cyliu/.venvs/py311/lib/python3.11/site-packages/traitsui/qt4/toolkit.py", line 237, in view_application
    return view_application.view_application(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cyliu/.venvs/py311/lib/python3.11/site-packages/traitsui/qt4/view_application.py", line 92, in view_application
    return ViewApplication(
           ^^^^^^^^^^^^^^^^
  File "/Users/cyliu/.venvs/py311/lib/python3.11/site-packages/traitsui/qt4/view_application.py", line 138, in __init__
    start_event_loop_qt4()
  File "/Users/cyliu/.venvs/py311/lib/python3.11/site-packages/pyface/util/guisupport.py", line 156, in start_event_loop_qt4
    app.exec()
  File "/Users/cyliu/.venvs/py311/lib/python3.11/site-packages/traitsui/qt4/toolkit.py", line 129, in eventFilter
    if event.type() == QtCore.QEvent.Type.KeyPress:
       ^^^^^^^^^^^^
  File "/Users/cyliu/.venvs/py311/lib/python3.11/site-packages/traitsui/qt4/toolkit.py", line 129, in eventFilter
    if event.type() == QtCore.QEvent.Type.KeyPress:
       ^^^^^^^^^^^^
  File "/Users/cyliu/.venvs/py311/lib/python3.11/site-packages/traitsui/qt4/toolkit.py", line 129, in eventFilter
    if event.type() == QtCore.QEvent.Type.KeyPress:
       ^^^^^^^^^^^^
  [Previous line repeated 6 more times]
  File "/Users/cyliu/.venvs/py311/lib/python3.11/site-packages/traitsui/qt4/ui_base.py", line 175, in closeEvent
    if self._ok_to_close():
       ^^^^^^^^^^^^^^^^^^^
  File "/Users/cyliu/.venvs/py311/lib/python3.11/site-packages/traitsui/qt4/ui_base.py", line 228, in _ok_to_close
    is_ok = not self.isModal()
                ^^^^^^^^^^^^^^
  File "/Users/cyliu/.venvs/py311/lib/python3.11/site-packages/traitsui/qt4/toolkit.py", line 129, in eventFilter
    if event.type() == QtCore.QEvent.Type.KeyPress:
       ^^^^^^^^^^^^
  File "/Users/cyliu/.venvs/py311/lib/python3.11/site-packages/traitsui/qt4/toolkit.py", line 129, in eventFilter
    if event.type() == QtCore.QEvent.Type.KeyPress:
       ^^^^^^^^^^^^
  File "/Users/cyliu/.venvs/py311/lib/python3.11/site-packages/traitsui/qt4/toolkit.py", line 129, in eventFilter
    if event.type() == QtCore.QEvent.Type.KeyPress:
       ^^^^^^^^^^^^
  [Previous line repeated 36 more times]
  File "/Users/cyliu/Documents/3.11_test/enable/enable/qt4/base_window.py", line 270, in leaveEvent
    self.handler.leaveEvent(event)
  File "/Users/cyliu/Documents/3.11_test/enable/enable/qt4/base_window.py", line 148, in leaveEvent
    self._enable_window._handle_mouse_event("mouse_leave", event)
  File "/Users/cyliu/Documents/3.11_test/enable/enable/abstract_window.py", line 349, in _handle_mouse_event
    mouse_event = self._create_mouse_event(event)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cyliu/Documents/3.11_test/enable/enable/qt4/base_window.py", line 515, in _create_mouse_event
    alt_down=bool(modifiers & QtCore.Qt.AltModifier),
                  ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
TypeError: unsupported operand type(s) for &: 'int' and 'KeyboardModifier'
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
    Note: This exception was delayed.
Exception ignored in: <function NativeScrollBar.__del__ at 0x11a772ac0>
Traceback (most recent call last):
  File "/Users/cyliu/Documents/3.11_test/enable/enable/qt4/scrollbar.py", line 99, in __del__
  File "/Users/cyliu/Documents/3.11_test/enable/enable/qt4/scrollbar.py", line 93, in destroy
RuntimeError: Internal C++ object (QResizableScrollBar) already deleted.
Exception ignored in: <function NativeScrollBar.__del__ at 0x11a772ac0>
Traceback (most recent call last):
  File "/Users/cyliu/Documents/3.11_test/enable/enable/qt4/scrollbar.py", line 99, in __del__
  File "/Users/cyliu/Documents/3.11_test/enable/enable/qt4/scrollbar.py", line 93, in destroy
RuntimeError: Internal C++ object (QResizableScrollBar) already deleted.

OS, Python version: [MacOS, python3.11]

package list: Package Version Editable project location


attrdict 2.0.1 attrdict3 2.0.2 chaco 5.1.0 /Users/cyliu/Documents/3.11_test/chaco configobj 5.0.8 enable 5.4.0.dev28 /Users/cyliu/Documents/3.11_test/enable fonttools 4.39.2 joblib 1.2.0 numpy 1.24.2 pandas 1.5.3 Pillow 9.4.0 pip 22.3.1 PyAudio 0.2.13 pyface 8.0.0 pygarrayimage 1.0 pyglet 2.0.5 /Users/cyliu/Documents/3.11_test/pyglet Pygments 2.14.0 pyparsing 3.0.9 PySide6 6.4.3 PySide6-Addons 6.4.3 PySide6-Essentials 6.4.3 python-dateutil 2.8.2 pytz 2023.2 reportlab 3.6.12 scikit-learn 1.2.2 scipy 1.10.1 setuptools 65.6.3 shiboken6 6.4.3 six 1.16.0 threadpoolctl 3.1.0 traits 7.0.0.dev1840 /Users/cyliu/Documents/3.11_test/traits traitsui 7.4.3 wxPython 4.2.0

homosapien-lcy commented 1 year ago

I found that if I remove the del method, which is responsible for desctroying the object from the python side, in the enable/enable/qt4/scrollbar.py (https://github.com/enthought/enable/blob/main/enable/qt4/scrollbar.py#L97), the error can be solved. But I'm not sure whether there is other essential functionality of this del function.

dpinte commented 1 year ago

Removing the __del__ method is not solving the problem. It just hides it. That can't be the solution.