chickadee » sdl2 » rw-from-blob

rw-from-blob blobprocedure

Create a new sdl2:rwops that accesses the memory of the given blob. You should close the sdl2:rwops when you are done with it, using rw-close! or one of the procedures that can automatically close the sdl2:rwops, such as load-bmp-rw.

Signals an exception of kind (exn sdl2) if an error occurs.

You can also use this procedure to create a sdl2:rwops from a SRFI-4 numeric vector, by first converting it to a blob using e.g. u8vector->blob/shared.

Caution: Creating a sdl2:rwops from a blob in CHICKEN-managed memory is unstable: the blob might be garbage collected or moved in memory, which would break the sdl2:rwops. To be safe, you should object-evict the blob and create the sdl2:rwops from the evicted blob (not the original). You may wish to object-release the evicted blob after you have closed the sdl2:rwops. Example:

(let* ((evicted-blob (object-evict '#${...}))
       (rwops (sdl2:rw-from-blob evicted-blob))
       (surf (sdl2:load-bmp-rw rwops #t)))
  (object-release evicted-blob)