changeset 82:9a69db231531

Fix async-layer copying wrong (not the most recently updated) buffer on screen.
author Mikhail Kryshen <mikhail@kryshen.net>
date Thu, 02 Sep 2010 04:29:21 +0400
parents 5d2153e8a28d
children b5bb0e16507d
files src/net/kryshen/indyvon/async.clj
diffstat 1 files changed, 13 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/net/kryshen/indyvon/async.clj	Thu Sep 02 03:55:44 2010 +0400
+++ b/src/net/kryshen/indyvon/async.clj	Thu Sep 02 04:29:21 2010 +0400
@@ -36,7 +36,7 @@
 ;;   :back
 ;;      being rendered to (offscreen)
 ;;   :fresh
-;;      offscreen rendering finished
+;;      most recently updated
 ;;   :free
 ;;      not in use
 
@@ -82,18 +82,21 @@
          readers (if (= state :front)
                    (dec (:readers buffer))
                    (:readers buffer))
+         fresh (delay (find-buffer @(:buffers al) :fresh))
          state (cond
                 (pos? readers) :front
-                (= :back (:state buffer)) :fresh
-                :default :free)]
-     (when (= state :fresh)
+                (= :back state) :fresh
+                @fresh :free
+                :default :fresh)]
+     (if (and (= state :fresh) @fresh)
        ;; Change state of the prefiously fresh buffer to :free.
-       (when-let [fresh (find-buffer @(:buffers al) :fresh)]
-         (alter (:buffers al) replace-buffer (assoc fresh
-                                               :state :free))))
-     (alter (:buffers al) replace-buffer (assoc buffer
-                                           :state state
-                                           :readers readers)))))
+       (alter (:buffers al)
+              replace-buffer (assoc @fresh
+                               :state :free)))
+     (alter (:buffers al)
+            replace-buffer (assoc buffer
+                             :state state
+                             :readers readers)))))
 
 (defmacro with-buffer
   {:private true}