|
From: Kris De S. <kri...@gm...> - 2007-10-31 21:02:47
|
Hi, I'm new to CL-SDL, and I'm not sure whether this is the right place to post this, but it's the best place I can think of. So here goes: I managed to get CL-SDL working with CMUCL on Mac OS X 10.4.10 Intel. This took some doing, so I thought I'd relate the how-to-do-it here so that others in a similar position as mine need not reinvent the wheel. I'm using CMUCL distribution cmucl-2007-10-x86-darwin, and CL-SDL version 0.2.2. I installed ASDF (don't know the exact version number) and UFFI 1.6.0. I used fink to install both SDL and Xorg. Fink installs SDL under "/sw/lib". This however is not part of the *library-paths* in ffi/uffi.lisp, so I added it there myself. If you set up ASDF, UFFI and CL-SDL, and try to run the examples at this point you will see two problems popping up: * Warning messages like the following: _NSAutoreleaseNoPool(): Object 0x349cc0 of class _NSThemeWidget autoreleased with no pool in place - just leaking * An error message: Uncaught exception: <NSInternalInconsistencyException> Error (1002) creating CGSWindow After the error the application will hang. The reason for this problem lies with the implementation of SDL on the mac. SDL uses Cocoa, and Cocoa applications need to be initalised in a certain way. This happens in SDL when one uses the SDL_main approach. That is, SDL provides a main method which sets up the Cocoa context and which then calls your own main method. However, as we're starting things from within the Lisp interpreter this doesn't work; we are way past the main method here. The solution is to redo the setup provided in SDL_main in the form of a separate function, and then call that. The implementation of that function can be found here: http://www.devolution.com/pipermail/sdl/2006-February/072880.html This is code in an e-mail by Ulrich von Zadow on the SDL mailing list. Copy that code into a file. I named it cocoa-util.m. This file may then be compiled into a dylib as follows: gcc -I /sw/include/SDL/ -fPIC -fno-common -c cocoa-util.m -o cocoa-util.o gcc -dynamiclib -framework cocoa cocoa-util.o -o libcocoautil.dylib Remember: /sw/include is where fink installs the header files. This may be a different location if you have installed SDL through some other method. By placing the dylib in a location where UFFI may find it, we can then use UFFI to provide access to the cocoa initialisation function: (uffi:load-foreign-library #p"/path/to/libcocoautil.dylib" :module "cocoautil") (uffi:def-function "CustomSDLMain" nil :returning :void) From this point on the all examples in CL-SDL will work without modification. Simply you precede their activation with a call to customsdlmain. I.e.: (customsdlmain)(nehe:run-tutorial 2) That's it. I haven't delved into the internals of the examples yet so I can't say for sure that they all do what they're supposed to do, but they seem to be okay. Anyway, cool project, and keep up the good work! Cheers, Kris |