lispgames / cl-sdl2

Common Lisp bindings for SDL2 using C2FFI.
MIT License
309 stars 82 forks source link

Crash on macOS High Sierra when running basic example in SBCL #104

Closed cbaggers closed 6 years ago

cbaggers commented 6 years ago

Steps to reproduce

Log

MacBook-Pro:Downloads Baggers$ sbcl
This is SBCL 1.4.4, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.
* (ql:quickload :sdl2/examples)                  
To load "sdl2/examples":
  Load 1 ASDF system:
    sdl2/examples
; Loading "sdl2/examples"
.........
(:SDL2/EXAMPLES)
* (sdl2-examples:basic-test)
Using SDL Library Version: 2.0.4
Setting up window/gl.
Opening game controllers.
Beginning main loop.
2018-04-13 13:13:26.993 sbcl[55736:1288570] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'nextEventMatchingMask should only be called from the Main Thread!'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff4389e6bb __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x00007fff6afb6942 objc_exception_throw + 48
    2   AppKit                              0x00007fff41541297 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 4167
    3   SDL2                                0x0000000001c2d5f5 SDL2 + 140789
    4   SDL2                                0x0000000001c178dd SDL2 + 51421
    5   ???                                 0x0000000022b58c2b 0x0 + 582323243
    6   ???                                 0x0000000022ba1fa5 0x0 + 582623141
    7   ???                                 0x0000000022ba1872 0x0 + 582621298
    8   ???                                 0x0000000022b79096 0x0 + 582455446
    9   ???                                 0x0000000022b79a2c 0x0 + 582457900
    10  ???                                 0x00000000228e22d9 0x0 + 579740377
    11  ???                                 0x0000000021ca5274 0x0 + 566907508
    12  ???                                 0x0000000021ca5747 0x0 + 566908743
    13  ???                                 0x0000000021ca4c68 0x0 + 566905960
    14  ???                                 0x0000000021b601b2 0x0 + 565576114
)
libc++abi.dylib: terminating with uncaught exception of type NSException
fatal error encountered in SBCL pid 55736(tid 0xb0000000):
SIGABRT received.

Welcome to LDB, a low-level debugger for the Lisp runtime environment.
cbaggers commented 6 years ago

First issue I found was that SDL2 itself was broken by high sierra so you have to update the dylibs. However even after that the example breaks.

CL-SDL2 itself is fine, I can create a context etc using cl-sdl2 from CEPL which doesnt use any other threads in the process.

This must be just an issue with the example

cbaggers commented 6 years ago

Just as a datapoint, this works perfectly:

(defun run1 ()
  (print "hi")
  (print "about to init")
  (sdl2:init)
  (unwind-protect
       (progn ()
          (print "init'd ok")
          (print "making an event we can poll into")
          (let ((event (sdl2:new-event)))
            (print "event created")
            (print "Next will poll a single event")
            (print (= 0  (sdl2:next-event event :poll nil)))
            (print "event poll'd")
            (print "now going to poll in a loop")
            (loop :until (= 0 (sdl2:next-event event :poll nil)))
            (print "loop poll worked")))
    (print "about to quit")
    (sdl2:quit)
    (print "successfully quit")))
mfiano commented 6 years ago

@cbaggers Would you consider a PR? I don't know of anyone else using macOS at this time.

cbaggers commented 6 years ago

@mfiano sure, I'll have to work out what it is first :) Im a bit stuck on another macOS cl-sdl2 threading issue right now. I'll probably file a ticket for it but I understand you wont be able to look at it

mfiano commented 6 years ago

Ok thanks. I really don't have the slightest about macOS and don't have the hardware available to test.

cbaggers commented 6 years ago

Ok closing this as the thread issue was me not reading the README. using make-this-thread-main set the correct main thread and so now the examples crash with the same segfault as Im seeing elsewhere. I'll open a new issue for that