diff options
author | David Thompson <dthompson2@worcester.edu> | 2020-10-12 08:37:55 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2020-10-12 08:37:55 -0400 |
commit | de4d9ac89f8811448035c5a77f5694dacafbe131 (patch) | |
tree | ece815cdc72c9f085b9b8eb688ecd56c80c988d3 | |
parent | d1920623156a2c35a2801be86398bae5674c64b7 (diff) |
graphics: buffer: Fix segfault in resize-buffer!
-rw-r--r-- | chickadee/graphics/buffer.scm | 16 |
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 ...) |