Tuesday, 29 January 2008

Getting started with clbuild and opengl


A script to update/install the latest versions of all the most important Common Lisp packages.

  -- clbuild project page

clbuild is a nice way to keep up to date on the latest libraries. An advantage over ASDF-INSTALL is that it can retrieve from more than just http. Look at Bill Clementson's blog for a good overview on how to get started. This post is about how to get started with cl-opengl(-thomas) with clbuild.

Once you have retrieved clbuild (lines prefixed by $ are what you would type in, everything else is output):


$ cd /path/to/clbuild
$ ./clbuild build cl-opengl
The following extra dependencies were found: alexandria babel cffi trivial-features
include dependencies in update? (Y/n)y
UPDATE darcs pull alexandria
Pulling from "http://common-lisp.net/project/alexandria/darcs/alexandria"...
No remote changes to pull in!
UPDATE darcs pull babel
Pulling from "http://common-lisp.net/~loliveira/darcs/babel"...
No remote changes to pull in!
UPDATE darcs pull cffi
Pulling from "http://common-lisp.net/~loliveira/darcs/cffi+lotsastuff"...
No remote changes to pull in!
UPDATE darcs pull cl-opengl
Pulling from "http://common-lisp.net/~loliveira/darcs/cl-opengl-thomas"...
No remote changes to pull in!
UPDATE darcs pull trivial-features
Pulling from "http://common-lisp.net/~loliveira/darcs/trivial-features"...
No remote changes to pull in!
update complete
20 system definition files registered
; loading system definition from
; /home/sohail/src/thirdparty/clbuild/systems/cl-ppcre.asd into
; #
; registering # as CL-PPCRE
Loading cl-glu...
Loading cl-glut-examples...
Loading cl-glut...
Loading cl-opengl...
Dumping monster.core...
[undoing binding stack and other enclosing state... done]
[saving current Lisp image into /home/sohail/src/thirdparty/clbuild/monster.core:
writing 2976 bytes from the read-only space at 0x01000000
writing 5424 bytes from the static space at 0x01100000
writing 33984512 bytes from the dynamic space at 0x09000000
done]

You can start the core as follows:

sbcl --core monster.core

Now, you might think you can just call (glut:init) and be off to the races, but you would be wrong:

* (glut:init)
*** glibc detected *** sbcl: free(): invalid pointer: 0x080876a8 ***
*** lockup ensues ***

The problem here is that when clbuild dumped core, the pointers for command line arguments are saved along with it. Unfortunately, these are FFI pointers and so the values are invalid. When you call glut:init, it tries to free these pointers which results in the lockup above. Luis Oliveira (luis on #lisp!) suggested that this is something CFFI should handle and said he would make a note of it.

In the meantime, you can execute the following to get around it:

* (progn (setq glut::*argcp* (cffi:null-pointer) glut::*argv* (cffi:null-pointer)))
#.(SB-SYS:INT-SAP #X00000000)

And now, you are good to go:

* (glut:init)
; No value
*

No comments: