ztellman / penumbra

not under active development - idiomatic opengl bindings for clojure
354 stars 43 forks source link

Patch: Small change to push-matrix #7

Closed elliottslaughter closed 15 years ago

elliottslaughter commented 15 years ago

Hi,

I made a small change to push-matrix on my local copy that I'm hoping you'll integrate into penumbra.

diff --git a/src/penumbra/opengl.clj b/src/penumbra/opengl.clj
index 68bc81a..dc8dfa3 100644
--- a/src/penumbra/opengl.clj
+++ b/src/penumbra/opengl.clj
@@ -88,9 +88,9 @@

 (defmacro push-matrix [& body]
   `(binding [*transform-matrix* (if *inside-begin-end* (atom @*transform-matrix*) *transform-matrix*)]
-    (if (not *inside-begin-end*) (gl-push-matrix))
-    ~@body
-    (if (not *inside-begin-end*) (gl-pop-matrix))))
+     (try (if (not *inside-begin-end*) (gl-push-matrix))
+          ~@body
+          (finally (if (not *inside-begin-end*) (gl-pop-matrix))))))

 (gl-facade-import glVertex3d vertex)
 (gl-facade-import glNormal3d normal)

Basically, I found myself in a situation where I actually cared what the return value of body of push-matrix was. The try block has the nice property that it returns that value. Coincidentally, it will also ensure the matrix gets popped in case an error occurs inside the body.

Thanks.

ztellman commented 15 years ago

Done and done.