cl-glfw3
cl-glfw3 copied to clipboard
Window just hangs when I close it
I'm on a Mac OS X
So here's a script that I'm runnning:
(ql:quickload :cl-glfw3)
(ql:quickload :cl-opengl)
(ql:quickload :trivial-main-thread)
(glfw:def-key-callback quit-on-escape (window key scancode action mod-keys)
(declare (ignore window scancode mod-keys))
(when (and (eq key :escape) (eq action :press))
(glfw:set-window-should-close)))
(defun render ()
(gl:clear :color-buffer)
(gl:with-pushed-matrix
(gl:color 1 1 1)
(gl:rect -25 -25 25 25)))
(defun set-viewport (width height)
(gl:viewport 0 0 width height)
(gl:matrix-mode :projection)
(gl:load-identity)
(gl:ortho -50 50 -50 50 -1 1)
(gl:matrix-mode :modelview)
(gl:load-identity))
(glfw:def-window-size-callback update-viewport (window w h)
(declare (ignore window))
(set-viewport w h))
(defun basic-window-example ()
;; Graphics calls on OS X must occur in the main thread
;; Though I have found that it works without this
(trivial-main-thread:with-body-in-main-thread ()
(glfw:with-init-window (:title "Window test" :width 600 :height 400)
(setf %gl:*gl-get-proc-address* #'glfw:get-proc-address)
(glfw:set-key-callback 'quit-on-escape)
(glfw:set-window-size-callback 'update-viewport)
(gl:clear-color 0 0 0 0)
(set-viewport 600 400)
(loop until (glfw:window-should-close-p)
do (render)
do (glfw:swap-buffers)
do (glfw:poll-events)))))
It is practically a clone of the basic window example (https://github.com/AlexCharlton/cl-glfw3/blob/master/examples/basic-window.lisp) but I've namespaced functions (trying to help myself learn 😄)
When I run it in the REPL, a window loads with a white rectangle, which is great. The only problem is that when I click the close button on the window, it doesn't close. The loop ends, but the window remains open.
~~I've tried adding~~
(glfw:destroy-window)
(glfw:terminate)
~~after the loop terminates but still no luck.~~
Edit: I see now that with-init-window
automatically destroys the window and terminates GLFW so there's no point adding more calls
Do you have any ideas?
This seems reminiscent of this problem: https://stackoverflow.com/q/22312630
But as far as I can tell the proposed solutions have already been done in the example
🤔
Thanks,
Luke
PS I'm finding this project greatly helpfulp in learning Common Lisp and feeling the power of setting up graphics on the fly in a REPL. Thanks!
I'm having the same problem with the vanilla cl-glfw3-examples:basic-window-example
on macOS Catalina 10.15.
I'm suspecting it's an incompatibility between macOS Catalina and the native glfw3
library, rather than an issue with this cl-glfw3
Lisp package.
SBCL version:
% sbcl --version
SBCL 1.5.7
To reproduce:
% sbcl
:
* (ql:quickload :cl-glfw3-examples)
* (cl-glfw3-examples:basic-window-example)
debugger invoked on a FLOATING-POINT-INVALID-OPERATION in thread
#<THREAD "main thread" RUNNING {10005084C3}>:
arithmetic error FLOATING-POINT-INVALID-OPERATION signalled
:
Stack trace:
0] backtrace
Backtrace for: #<SB-THREAD:THREAD "main thread" RUNNING {10005084C3}>
0: ("bogus stack frame")
1: ("foreign function: InstallEventLoopTimerInternal")
2: ("foreign function: InstallActivateTSMDocument_Timer")
3: ("foreign function: MyDeactivateTSMDocument")
4: ("foreign function: DeactivateTSMDocument")
5: ("foreign function: -[NSTextInputContext deactivate]")
6: ("foreign function: +[NSTextInputContext currentInputContext_withFirstResponderSync:]")
7: ("foreign function: -[NSView _setWindow:]")
8: ("foreign function: __21-[NSView _setWindow:]_block_invoke_2")
9: ("foreign function: -[NSView _setWindow:]")
10: ("foreign function: -[NSWindow dealloc]")
11: ("foreign function: -[NSWindow _dealloc]")
12: ("foreign function: _ZN19AutoreleasePoolPage12releaseUntilEPP11objc_object")
13: ("foreign function: objc_autoreleasePoolPop")
14: ("foreign function: glfwDestroyWindow")
15: (%CL-GLFW3:DESTROY-WINDOW :INVALID-VALUE-FOR-UNESCAPED-REGISTER-STORAGE)
16: (CL-GLFW3:DESTROY-WINDOW #.(SB-SYS:INT-SAP #X00352490))
:
GLFW version:
So it seems to fail in code triggered by the glfw
library. I have:
% brew info glfw
glfw: stable 3.3 (bottled), HEAD
:
Startup:
I've also seen it crash with the same exception at start-up, triggered by a different code path:
0] backtrace
Backtrace for: #<SB-THREAD:THREAD "main thread" RUNNING {10005084C3}>
0: ("bogus stack frame")
1: ("foreign function: hashProbe")
2: ("foreign function: -[NSConcreteHashTable addObject:]")
3: ("foreign function: -[NSCGLSurface flushRect:]")
4: ("foreign function: NSCGLSurfaceFlush")
5: ("foreign function: glSwap_Exec")
6: ("foreign function: CGLFlushDrawable")
7: ("foreign function: -[NSOpenGLContext flushBuffer]")
8: ("foreign function: swapBuffersNSGL")
9: (%CL-GLFW3:SWAP-BUFFERS :INVALID-VALUE-FOR-UNESCAPED-REGISTER-STORAGE)
10: ((LAMBDA NIL :IN CL-GLFW3-EXAMPLES:BASIC-WINDOW-EXAMPLE))
:
I also have the same issue.
- glfw: stable 3.3.8 (bottled), HEAD
- SBCL 2.3.9
- OSX 14.1
I did a bit of searching and testing and found this reddit thread:
- https://www.reddit.com/r/Common_Lisp/comments/wmvk11/sbcl_with_opengl_on_macos_possible/
The following code works for me:
(trivial-main-thread:call-in-main-thread
(lambda ()
(sb-int:set-floating-point-modes :traps nil)
(cl-glfw3-examples:basic-window-example)))