Hi all:
While resurrecting Kenny Tilton's Cello and trying to reuse some code of the cl-opengl bindings (trying to unite the two) I came across this error:
Source:
(define-foreign-library OpenGL (:darwin (:framework "OpenGL")) (:windows "opengl32.dll" :calling-convention :stdcall) (:unix (:or "libGL.so" "libGL.so.2" "libGL.so.1")))
(use-foreign-library OpenGL)
(define-foreign-library GLU (:windows "glu32.dll") ((:and :unix (:not :darwin)) (:or "libGLU.so.1" "libGLU.so")) ((:not :darwin) (:default "libGLU")))
(use-foreign-library GLU)
(defconstant GL_VERSION #x1f02) (defctype GLenum :unsigned-int)
(defmacro defglfun ((cname lname) result-type &body body) `(progn (declaim (inline ,lname)) (defcfun (,cname ,lname :library OpenGL) ,result-type ,@body)))
(defglfun ("glGetString" %glGetString) :pointer (name GLenum))
(defun gl-get-version () (let ((version-string (%glGetString GL_VERSION))) ;; <<<<---- BUS ERROR ! (break) (foreign-string-to-lisp version-string)))
REPL:
; Foreign loading /System/Library/Frameworks/OpenGL.framework/OpenGL. CL-USER > (gl-get-version) Bus Error (Signal 10)
Oh, btw, that happens no matter what function from OpenGL I try to call... So, something very fundamental must be wrong here. I just can't see what ... Please help!
TIA!!!!
Best, Frank
Frank Goenninger wrote:
Have you asked gdb for help, too?
Leslie
Am 08.05.2009 um 15:43 schrieb Leslie P. Polzer:
Hadn't until you asked. But now I have. I started AllegroCL with
$ alisp
and then loaded my system via ASDF.
CL-USER > (asdf 'cello-nx)
... messages as expected ...
CL-USER >
At this point I started gdb and attached to the process. After enabling out logging I continued the alisp process.
CL-USER > (cello-nx::gl-get-version)
which caused the following output:
Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_PROTECTION_FAILURE at address: 0x00000000
I then asked gdb to print the backtrace:
0x95a1d2ec in glGetError () #0 0x95a1d2ec in glGetError () #1 0x00243b68 in ff_funcall () at qrff.s:253 #2 0x002439b2 in ff_apply () at qrff.s:97 #3 0x032e100b in ?? () #4 0x10a2fc05 in ?? () #5 0x1088f3e5 in ?? () #6 0x1066add8 in ?? () #7 0x0310dab8 in ?? () #8 0x0331b281 in ?? () #9 0x03310f1d in ?? () #10 0x03320a17 in ?? () #11 0x0310e680 in ?? () #12 0x00259097 in apply () at qruntime.s:1901 #13 0x0331e05e in ?? () #14 0x03331c6f in ?? () #15 0x00259097 in apply () at qruntime.s:1901 #16 0x03016a08 in ?? () #17 0x0332e9a2 in ?? () #18 0x03016f9c in ?? () #19 0x0310e8c7 in ?? () #20 0x002544be in first_lisp_thread () at qrstorag.s:3081 #21 0x002542aa in _start_reborn_lisp () at qrstorag.s:2889 #22 0x00233f65 in startup_lisp () at c/startup.c:1290 #23 0x00253de7 in cont_setstack () at qrstorag.s:2408 #24 0x00253c7b in _first_lisp_thread_init () at qrstorag.s:2288
The two functions involved here are: (point where the bus error occurs is marked <<<<<<<<<<)
(defun! gl-check-error (&optional (id :anonymous) announce-success) (if (null (find id *gl-list-of-ids-excluded-from-error-checking*)) (if (and (boundp '*gl-begun*) *gl-begun*) (progn (logmsg :DEBUG *this-file* *this-module* 3 "Not checking OpenGL errors inside glBegin/glEnd at ~S." id)) (let ((e (%glGetError))) ;; ffi glGetError <<<<<<<<<<< (if (= e 0) (when announce-success (logmsg :DEBUG *this-file* *this-module* 4 "No OpenGL error found at ~S" id)) (progn (if (boundp '*gl-stop*) (logmsg :ERROR *this-file* *this-module* 5 "*gl-stop* bound at ~S." id)) (setf *gl-stop* t) (let* ((err-text (foreign-string-to-lisp (%gluErrorString e))) (msg (format nil "OpenGL error ~d ("~A") at ~S" e err-text id))) (logmsg :ERROR *this-file* *this-module* 6 msg) (when *gl-break-on-stop* (break msg)))))))))
(defun gl-get-version () (gl-check-error t) (let ((version-string (%glGetString GL_VERSION))) (break) (foreign-string-to-lisp version-string)))
Ok, so back to my assessment: Something fundamental not working here.
I do get the same error happening when I do not call the cl-check- error function but go straight to call %glGetString (which calls glGetString ffi function).
It just seems as if the OpenGL lib is not really loaded and the function address of the foreign functions are null pointers...
Any further suggestions of what I should analyze in gdb or elsewhere? Educated guesses on the causes? Thanks!!!
Ah, you know, it worked last time (half a year ago, on a different OS patch level of OS X, with fewer patches loaded for AllegroCL and older version of CFFI).
Cheers Frank
-- Frank Goenninger
Cell: +49 175 4321058 E-Mail: frgo@me.com
In addition to the GDB session below I tried some more analysis on the Lisp side:
CL-USER> (foreign-symbol-pointer "glGetError") 2510410464 CL-USER> (foreign-funcall-pointer (foreign-symbol-pointer "glGetError") () :void :unsigned-int) Received signal number 10 (Bus error) ...
I admit I am out of clues as to what I should analyse further ...
Frank
Anfang der weitergeleiteten E-Mail:
-- Frank Goenninger
Cell: +49 175 4321058 E-Mail: frgo@me.com
Am 08.05.2009 um 20:30 schrieb Mark Hoemmen:
Not really in this case. The function glGetError is defined as
GLenum glGetError(void);
So, no arguments passed. Just an unsigned int returned (that's what GLenum is typedef'ed to).
Cheers Frank
-- Frank Goenninger
Cell: +49 175 4321058 E-Mail: frgo@me.com
Another piece of info that makes me look - shocked:
1. I loaded the cl-opengl OpenGL bindings from common-lisp.net once again. 2. I just started my lisp process and loaded the cl-opengl package via ASDF 3. A simple (gl:get-error) results in exactly the same error - but no other package is loaded, so I am assuming cl-opengl is not the root cause of this.
Hmpf.
Another piece:
Warning: foreign ARG type :CHAR not compatible with lisp type (INTEGER -128 127) Warning: foreign ARG type :UNSIGNED-CHAR not compatible with lisp type (INTEGER 0 255)
I get these warnings and ignored them so far. I seem to remember that I haven't seen these with older versions of AllegroCL and CFFI.
AllegroCL is version 8.1 with up-to-date patches. CFFI is latest version from darcs.
???
Cheers Frank
-- Frank Goenninger
Cell: +49 175 4321058 E-Mail: frgo@me.com
I think the problem is that OpenGL on the Mac must be connected to a rendering engine in the thread where you call it. I get crashes with the LispWorks OpenGL code too unless I call glGetString from the event loop thread after starting the OpenGL demo.
__Martin
Am 08.05.2009 um 21:54 schrieb Martin Simmons:
Yes, thanks Martin, I know that this is a requirement on OS X. There is just one thread running...
Cheers Frank
-- Frank Goenninger
Cell: +49 175 4321058 E-Mail: frgo@me.com
For the records and for the archives:
The error described below is a result of not having created a valid OpenGL context (= window) before calling an OpenGL function. No matter what function gets called before having a windows OpenGL is quite unforgiving and will crash the app with a bus error.
So, OpenGL does not even allow for querying the version info without a window ...
Well, not to be forgotten - it was one of those Unknown Unknowns.
;-)
Thanks to everybody for the feedback, help and support.
Cheers Frank
Am 08.05.2009 um 14:48 schrieb Frank Goenninger:
-- Frank Goenninger
Cell: +49 175 4321058 E-Mail: frgo@me.com