vydd / sketch

A Common Lisp framework for the creation of electronic art, visual design, game prototyping, game making, computer graphics, exploration of human-computer interaction, and more.
MIT License
1.4k stars 67 forks source link

Fixed double free issue in SBCL for sdl2-ttf #36

Closed compmstr closed 4 years ago

compmstr commented 4 years ago

As per: https://github.com/Failproofshark/cl-sdl2-ttf/issues/16 , sdl2-ttf uses finalizers to free the SDL surfaces generated when rendering text. This was causing sketches to crash (at least on Linux/SBCL) whenever I had text being rendered. I updated the make-image-from-surface function to optionally take in a :free-surface keyword, which if nil, means it won't free the surface manually.

I also moved the text line image generation into it's own function, so that static text can be cached and reused instead of being rendered and sent to the GPU every frame.

I didn't seem to have the same issue with CCL on OSX, but making this change definitely fixed the constant crashes in SBCL, and it still works within CCL from my testing.

Leaving the app running with this new code didn't appear to have any effect on memory usage.