summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2020-10-12 08:37:55 -0400
committerDavid Thompson <dthompson2@worcester.edu>2020-10-12 08:37:55 -0400
commitde4d9ac89f8811448035c5a77f5694dacafbe131 (patch)
treeece815cdc72c9f085b9b8eb688ecd56c80c988d3
parentd1920623156a2c35a2801be86398bae5674c64b7 (diff)
graphics: buffer: Fix segfault in resize-buffer!
-rw-r--r--chickadee/graphics/buffer.scm16
1 files changed, 9 insertions, 7 deletions
diff --git a/chickadee/graphics/buffer.scm b/chickadee/graphics/buffer.scm
index 40ebce8..8a30ea3 100644
--- a/chickadee/graphics/buffer.scm
+++ b/chickadee/graphics/buffer.scm
@@ -234,13 +234,15 @@ resized."
(let ((old-bv (buffer-data buffer)))
(set-buffer-length! buffer length)
(when old-bv
- (unmap-buffer! buffer)
- ;; TODO: Set map mode in record
- (map-buffer! buffer 'write-only)
- (let ((new-bv (buffer-data buffer)))
- (bytevector-copy! old-bv 0 new-bv 0
- (min (bytevector-length old-bv)
- (bytevector-length new-bv))))))
+ ;; Need to make a copy of the data.
+ (let ((old-bv (bytevector-copy old-bv)))
+ (unmap-buffer! buffer)
+ ;; TODO: Set map mode in record
+ (map-buffer! buffer 'write-only)
+ (let ((new-bv (buffer-data buffer)))
+ (bytevector-copy! old-bv 0 new-bv 0
+ (min (bytevector-length old-bv)
+ (bytevector-length new-bv)))))))
(error "cannot resize static buffer")))
(define-syntax-rule (with-mapped-buffer buffer body ...)