Debugging a Callback

Willem Rein Oudshoorn woudshoo at xs4all.nl
Fri Jun 21 07:50:09 UTC 2013


James Ashley <james.ashley at gmail.com> writes:

> I don't have a minimal test-case to share, yet. That's my next step. I'm
> being lazy and asking before I start trying to trim pieces down. The best
> nutshell of the problem I have at the moment is that the callback in
> question looks like:
>
> (cffi:defcallback window-sizer
>     :void
>   ((window glfw3::glfw-window) (width :int) (height :int))

...
>   (gl:viewport 0 0 width height)
...

>   (let ((ratio (/ width height)))
>     (format t "Setting ortho: ~A~%" ratio)
>     ;; This next line is failing here, pretty spectacularly.
>     ;; with an error message that doesn't seem to make any sense.
>     ;; It appears to run fine (even if it does nothing) when
>     ;; I run it throuh the REPL.
>     (gl:ortho (- ratio) ratio -1 1 1 -1))
>   (format t "Returning~%"))
>
> The stack trace (FWIW) looks like:
> The value 17465867632912 is not of the expected type DOUBLE-FLOAT.
>    [Condition of type TYPE-ERROR]
>
> Just for the record, I'm much more interested in learning how I can
> diagnose and fix these sorts of problems for myself than anything else. I
> just seemed to run into a total dead end on google.

Here are my two cents.  I have been using cl-opengl with CCL on OSX and
I have noticed a few times that either cl-opengl, cffi or the ffi of CCL 
are picky about the exact numerical types that are passed.

So your problem is most likely not in the callback,
but either in the gl:viewport of gl:ortho call.

Try coercing the arguments to a float before calling the gl:ortho
function.

Disclaimer, this is from memory and from personal anecdotal evidence, so
most likely very unreliable.

Debugging wise, it looks to me that the cffi:defcallback has created a
function.  Maybe you can macro expand the callback definition (maybe
more than once) and see
what it tries to do. 

Kind regards,
Wim Oudshoorn.





More information about the cffi-devel mailing list