pyglet: Window buttons on mac cause python/pyglet to crash
Description: The window buttons (close, minimize, full screen) cause python to crash in various ways. (Segmentation fault, Recursion Error, Abort Trap, Illegal Instruction).
Pyglet version(s): 1.4.1
Python version(s): 3.7
OS: OS X 10.14.5 (Seems to only affect newer Macbooks)
Related tickets: bitbucket #199 bitbucket #229
Minimal example:
import pyglet
pyglet.window.Window(resizable=True)
pyglet.app.run()
Output 1 (close):
$ python3 example.py
Traceback (most recent call last):
File "_ctypes/callbacks.c", line 232, in 'calling callback function'
File "/usr/local/lib/python3.7/site-packages/pyglet/libs/darwin/cocoapy/runtime.py", line 1120, in objc_method
args = convert_method_arguments(encoding, args)
File "/usr/local/lib/python3.7/site-packages/pyglet/libs/darwin/cocoapy/runtime.py", line 1000, in convert_method_arguments
new_args.append(ObjCInstance(a))
File "/usr/local/lib/python3.7/site-packages/pyglet/libs/darwin/cocoapy/runtime.py", line 921, in __new__
if not isinstance(object_ptr, c_void_p):
RecursionError: maximum recursion depth exceeded while calling a Python object
Segmentation fault: 11
$
Output 2 (minimize):
$ python3 example.py
Traceback (most recent call last):
File "_ctypes/callbacks.c", line 232, in 'calling callback function'
File "/usr/local/lib/python3.7/site-packages/pyglet/libs/darwin/cocoapy/runtime.py", line 1120, in objc_method
args = convert_method_arguments(encoding, args)
File "/usr/local/lib/python3.7/site-packages/pyglet/libs/darwin/cocoapy/runtime.py", line 1000, in convert_method_arguments
new_args.append(ObjCInstance(a))
File "/usr/local/lib/python3.7/site-packages/pyglet/libs/darwin/cocoapy/runtime.py", line 921, in __new__
if not isinstance(object_ptr, c_void_p):
RecursionError: maximum recursion depth exceeded while calling a Python object
Illegal instruction: 4
$
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 23 (21 by maintainers)
Commits related to this issue
- Added example which reproduces the recursive pyglet crash Issue: https://github.com/pyglet/pyglet/issues/5 Signed-off-by: Ole Herman Schumacher Elgesem <oleherman93@gmail.com> — committed to olehermanse/cocoa-python by olehermanse 5 years ago
- Fix infinite recursion error on OSX #5 — committed to pyglet/pyglet by benmoran56 4 years ago
- Fix infinite recusion during window operations on macOS cocoapy function `send_super()` which is supposed to call a method on the superclass sometimes calls the method on the object class instead lea... — committed to eterevsky/pyglet by eterevsky 4 years ago
- In cases where cocoapy resolves superclass incorrectly, force superclass resolution by name. Fixes #5 — committed to eterevsky/pyglet by eterevsky 4 years ago
- Fix infinite recursion error on OSX #5 — committed to pyglet/pyglet by benmoran56 4 years ago
I forked cocoa-python here:
https://github.com/olehermanse/cocoa-python
And reproduced the issue, with a quite small example:
https://github.com/olehermanse/cocoa-python/commit/dc536717f0dcf9f008108a882ccb0955135160eb
So, there are many other examples where
send_super()from cocoa-python works, however, in this example it doesn’t. When you call send_super, it seems to callMyWindow.nextEventMatchingMaskUntilDateinstead ofNSWindow.nextEventMatchingMaskUntilDate.To reproduce:
Note: I thought
setFrameSizehad the same problem asnextEventMatchingMaskUntilDate, but that is just because it callsnextEventMatchingMaskUntilDateinternally.We had a pretty long session last night trying to find the root cause. The newer macbooks are indeed sending different data in some events and the current cocoa wrapper is not equipped to deal with it. @olehermanse is testing out PyCocoa now (more recent project).
I have no idea how Cocoa or ObjC works, but here’s a dirty hack of cocoapy that makes window operations work:
I was able to reproduce this issue on my 2018 Macbook Pro 15 inch w/ touchbar. Got the same output as @olehermanse when minimizing and closing. Also, manually resizing the window by dragging causes a segfault with the same output as closing.
Pyglet version(s): 1.4.1 Python version(s): 3.7.3 OS: macOS 10.14.5