On Sat, 11 Jul 2009 21:59:52 -0700, Elliott Slaughter <elliottslaugh...@gmail.com> wrote:
> I ran into a little trouble when the example got the pixels from the > surface: > > surface->pixels > > What I eventually got working in lisp is: > > (sdl-base::with-pixels (pixels (sdl:fp surface)) > (sdl-base::pixel-data pixels)) > > Which seems to work ok. (But I'd still like confirmation that this is the > best way to do it. It seems like too much code to do something so > simple.) It is not the 'best' way to do it, but it currently is the only way to do it. This hasn't been made into a function call because no-one requested it. Note that WITH-PIXELS locks the surface before the pixels can be accessed, which is a sdl requirement. Sounds like you have something already? > My second question is about how to free the texture after I'm done. I > know > this isn't really an SDL thing, but I figured you dealt with this when > you > created lisp wrappers around SDL surfaces. For OpenRM, yes. I use a combination of the CFFI finalizers (when SDL pixel data are copied from the SDL surface) as well as OpenRM callbacks (when SDL pixel data are shared between SDL surface and OpenGL texture) to free image data. > My intuition would be to create a finalizer for the wrapper, and free the > texture then. But according to trivial-garbage [2], in some lisps it > isn't > safe to use an object when the finalizer is called. (Or does CFFI do this > automatically for me?) By the time the finalizer is called the Lisp object is no more. All the finalizer can do is to call a closure which contains the foreign memory to free. Any attempt by the finalizer to access any slot in the Lisp object usually results in a swift visit from the debugger. Take a look at sdl/rectangle.lisp; RECTANGLE inherits from FOREIGN-OBJECT. FOREIGN-OBJECT is defined in sdl/base.lisp. FOREIGN-OBJECT specifies an initialize-instance AROUND method that will create a finalizer based on the :GC and :FREE initargs. :GC determines if the finalizer should run when the object is garbage collected, and :FREE specifies the function that will free the foreign memory. :FREE is called either by the finalizer or explicitly when the object is free'd using FREE. - Luke _______________________________________________ application-builder mailing list application-builder@lispniks.com http://www.lispniks.com/mailman/listinfo/application-builder