From aeee49735bc5a00aa71d4b3c88ddcf625813d0ab Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 3 Feb 2024 17:01:48 -0500 Subject: 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. --- chickadee/graphics/buffer.scm | 8 +++++--- 1 file 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)))) -- cgit v1.2.3