moderngl / moderngl-window

A cross platform utility library for ModernGL making window creation and resource loading simple
MIT License
246 stars 61 forks source link

Unhandled exception when click ESC to exit program #190

Closed Peter0923 closed 8 months ago

Peter0923 commented 8 months ago

There is always an unhanled exception when I click escape key to exit program:

Exception ignored on calling ctypes callback function: <function ObjCSubclass.method.<locals>.decorator.<locals>.objc_method at 0x115f391c0>
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyglet/libs/darwin/cocoapy/runtime.py", line 1251, in objc_method
    result = f(py_self, *args)
             ^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyglet/window/cocoa/pyglet_view.py", line 187, in keyDown_
    self._window.dispatch_event('on_key_press', symbol, modifiers)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyglet/window/__init__.py", line 671, in dispatch_event
    super().dispatch_event(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyglet/event.py", line 380, in dispatch_event
    if handler(*args):
       ^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/moderngl_window/context/pyglet/window.py", line 216, in on_key_press
    self.close()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/moderngl_window/context/pyglet/window.py", line 184, in close
    self._window.close()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyglet/window/cocoa/__init__.py", line 244, in close
    super(CocoaWindow, self).close()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyglet/window/__init__.py", line 666, in close
    app.event_loop.dispatch_event('on_window_close', self)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyglet/event.py", line 392, in dispatch_event
    raise e
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyglet/event.py", line 387, in dispatch_event
    if getattr(self, event_type)(*args):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyglet/app/base.py", line 286, in on_window_close
    self.exit()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyglet/app/cocoa.py", line 112, in exit
    self.platform_event_loop.notify()
    ^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'CocoaAlternateEventLoop' object has no attribute 'platform_event_loop'

It is always reproducible only if the Window is based on Pyglet. My PC is Apple M1.

einarf commented 8 months ago

What version of pyglet is installed? I recently bumped this from a 2.0 pre-release to latest 2.0.x.

einarf commented 8 months ago

Related to this https://github.com/pyglet/pyglet/pull/1059

einarf commented 8 months ago

If you simply upgrade your pyglet version it might actually fix it.

pip install -I pyglet==2.0.14
Peter0923 commented 8 months ago

I was using 2.0.12. Now it is solved after upgrading it to the latest version (2.0.14). Thank you @einarf!