Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when compiling def-key-callback forms #42

Open
Odddity opened this issue Aug 11, 2023 · 1 comment
Open

Error when compiling def-key-callback forms #42

Odddity opened this issue Aug 11, 2023 · 1 comment

Comments

@Odddity
Copy link

Odddity commented Aug 11, 2023

When I try to compile a def-key-callback form in SBCL with sly, it signals an error:

failed AVER:
    (MEMBER SB-C::CLAMBDA
            (SB-C::COMPONENT-LAMBDAS
             (SB-C::LAMBDA-COMPONENT SB-C::CLAMBDA)))
This is probably a bug in SBCL itself. (Alternatively, SBCL
might have been corrupted by bad user code, e.g. by an undefined
Lisp operation like (FMAKUNBOUND 'COMPILE), or by stray pointers
from alien code or from unsafe Lisp code; or there might be a
bug in the OS or hardware that SBCL is running on.) If it seems
to be a bug in SBCL itself, the maintainers would like to know
about it. Bug reports are welcome on the SBCL mailing lists,
which you can find at <http://sbcl.sourceforge.net/>.
   [Condition of type SB-INT:BUG]

I can evaluate the def-key-callback form, and the callback works correctly when I run the program. It's only compiling that signals the error.

The error occurs under Linux (manjaro), SBCL v2.3.7, but doesn't occur when I compile under Windows.

@Odddity
Copy link
Author

Odddity commented Sep 19, 2023

After further investigation, I think it might not be a problem with cl-glfw but maybe with cl-opengl, or maybe I'm doing something wrong that I can't understand.

Compiling a file with this code in it is OK (does not signal a condition):

(defun toggle-wireframe-mode ()
  (if (setf *wireframe-mode* (not *wireframe-mode*))
      (gl:polygon-mode :front-and-back :line)
      (gl:polygon-mode :front-and-back :fill)))

(def-key-callback key-callback (window key scancode action mod)
  (declare (ignore window scancode mod))
  (flet ((pressedp (keysym)
           (and (eq key keysym) (eq action :press))))
    (when (pressedp :escape)
      (set-window-should-close))
    (when (pressedp :semicolon)
      (toggle-wireframe-mode))))

However, this form does signal the "failed AVER" error:

(def-key-callback key-callback (window key scancode action mod)
  (declare (ignore window scancode mod))
  ;; (format t "~&~S" (list :key key :action action :mod mod))
  (flet ((pressedp (keysym)
           (and (eq key keysym) (eq action :press))))
    (when (pressedp :escape)
      (set-window-should-close))
    (when (pressedp :semicolon)
      (if (setf *wireframe-mode* (not *wireframe-mode*))
          (gl:polygon-mode :front-and-back :line)
          (gl:polygon-mode :front-and-back :fill)))))

Further poking around shows that compiling a def-key-callback form that has any OpenGL calls it in it will signal the error at compilation time. Example:

(def-key-callback key-callback (window key scancode action mod)
  (declare (ignore window scancode mod key action))
  (gl:polygon-mode :front-and-back :line))

Maybe something to do with no OpenGL context being available during compilation, but I don't see why that would be a problem since compiling the macro shouldn't actually make any OpenGL calls. Error occurs in SBCL but not CCL.

Anyway, I've got no further ideas and I'm not even sure if it's a problem for this library to fix. But I can take care of it by putting all OpenGL calls in their own functions and calling those functions from my key callback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant