summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2024-02-03 17:01:48 -0500
committerDavid Thompson <dthompson2@worcester.edu>2024-02-03 17:07:09 -0500
commitaeee49735bc5a00aa71d4b3c88ddcf625813d0ab (patch)
tree2a045731ada0c467d8798f340e554218d2e2f7d9
parent6f17c3561536540ec2a9c5076f5ed916136f87e1 (diff)
graphics: buffer: Check length in pointer->bytevector/cached.
Since buffers can be resized in place (currently, they won't be once the graphics rewrite lands) we need to check that the cached bytevector is of the desired length before considering it to be a cache hit.
-rw-r--r--chickadee/graphics/buffer.scm8
1 files changed, 5 insertions, 3 deletions
diff --git a/chickadee/graphics/buffer.scm b/chickadee/graphics/buffer.scm
index f2fbfe0..625a9e0 100644
--- a/chickadee/graphics/buffer.scm
+++ b/chickadee/graphics/buffer.scm
@@ -237,9 +237,11 @@ never sent to the GPU."
;; those memory regions we avoid bytevector allocation after a frame
;; or two of warmup.
(define (pointer->bytevector/cached buffer pointer length)
- (let ((cache (buffer-stream-cache buffer))
- (address (pointer-address pointer)))
- (or (hashv-ref cache address)
+ (let* ((cache (buffer-stream-cache buffer))
+ (address (pointer-address pointer))
+ (cached (hashv-ref cache address)))
+ (if (and cached (= (bytevector-length cached) length))
+ cached
(let ((bv (pointer->bytevector pointer length)))
(hashv-set! cache address bv)
bv))))