summaryrefslogtreecommitdiff
path: root/2d/texture.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2014-02-09 13:01:23 -0500
committerDavid Thompson <dthompson2@worcester.edu>2014-02-09 13:01:23 -0500
commit44f4d45b65ad9400417dc5e71a36b2372c0eb113 (patch)
tree40aa5c6ffcd68c4b2a447080b97aff53c9fbac50 /2d/texture.scm
parent3267fc1ace530a37fecd05d0838809c6f0af22a7 (diff)
Add define-guardian macro.
* 2d/helpers.scm (define-guardian): New macro. * 2d/texture.scm (reap-textures): Delete it. (texture-guardian): Defined using define-guardian.
Diffstat (limited to '2d/texture.scm')
-rw-r--r--2d/texture.scm24
1 files changed, 8 insertions, 16 deletions
diff --git a/2d/texture.scm b/2d/texture.scm
index daa0568..faa2359 100644
--- a/2d/texture.scm
+++ b/2d/texture.scm
@@ -93,22 +93,14 @@ that will be rendered, in pixels."
;; Use a guardian and an after GC hook that ensures that OpenGL
;; textures are deleted when texture objects are GC'd.
-(define texture-guardian (make-guardian))
-
-(define (reap-textures)
- (let loop ((texture (texture-guardian)))
- (when texture
- ;; Do not reap texture regions
- (unless (texture-region? texture)
- ;; When attempting to reap structures upon guile exit, the
- ;; dynamic pointer to gl-delete-textures becomes invalid. So, we
- ;; ignore the error and move on.
- (catch 'misc-error
- (lambda () (gl-delete-texture (texture-id texture)))
- (lambda (key . args) #f)))
- (loop (texture-guardian)))))
-
-(add-hook! after-gc-hook reap-textures)
+(define-guardian texture-guardian
+ (lambda (texture)
+ ;; Do not reap texture regions
+ (unless (texture-region? texture)
+ ;; When attempting to reap structures upon guile exit, the
+ ;; dynamic pointer to gl-delete-textures becomes invalid. So, we
+ ;; ignore the error and move on.
+ (false-if-exception (gl-delete-texture (texture-id texture))))))
(define (bitmap->texture bitmap)
"Translates a freeimage bitmap into an OpenGL texture."