# Buggy code
def setFrameSize_(self, size):
    # This method is called when view is first installed as the
    # contentView of window.  Don't do anything on first call.
    # This also helps ensure correct window creation event ordering.
    if not self._window.context.canvas:
        cocoapy.send_super(
            self,
            "setFrameSize:",
            size,
            preventSuperclassRecursion=False,
            argtypes=[cocoapy.NSSize],
        )
        return

    cocoapy.send_super(
        self,
        "setFrameSize:",
        size,
        preventSuperclassRecursion=True,
        argtypes=[cocoapy.NSSize],
    )

    width, height = int(size.width), int(size.height)
    self._window.switch_to()
    self._window.context.update_geometry()
    self._window.dispatch_event("on_resize", width, height)
    self._window.dispatch_event("on_expose")
    # Can't get app.event_loop.enter_blocking() working with Cocoa, because
    # when mouse clicks on the window's resize control, Cocoa enters into a
    # mini-event loop that only responds to mouseDragged and mouseUp events.
    # This means that using NSTimer to call idle() won't work.  Our kludge
    # is to override NSWindow's nextEventMatchingMask_etc method and call
    # idle() from there.
    if self.inLiveResize():
        from pyglet import app

        if app.event_loop is not None:
            app.event_loop.idle()


# Traceback (RecursionError)
$ 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
$

# Fixed code
def setFrameSize_(self, size):
    cocoapy.send_super(
        self, "setFrameSize:", size, superclass_name="NSView", argtypes=[cocoapy.NSSize]
    )

    # This method is called when view is first installed as the
    # contentView of window.  Don't do anything on first call.
    # This also helps ensure correct window creation event ordering.
    if not self._window.context.canvas:
        return

    width, height = int(size.width), int(size.height)
    self._window.switch_to()
    self._window.context.update_geometry()
    self._window.dispatch_event("on_resize", width, height)
    self._window.dispatch_event("on_expose")
    # Can't get app.event_loop.enter_blocking() working with Cocoa, because
    # when mouse clicks on the window's resize control, Cocoa enters into a
    # mini-event loop that only responds to mouseDragged and mouseUp events.
    # This means that using NSTimer to call idle() won't work.  Our kludge
    # is to override NSWindow's nextEventMatchingMask_etc method and call
    # idle() from there.
    if self.inLiveResize():
        from pyglet import app

        if app.event_loop is not None:
            app.event_loop.idle()