diff --git a/common/src/app/common/types/fills/impl.cljc b/common/src/app/common/types/fills/impl.cljc index 26f3757c6e..beebc29655 100644 --- a/common/src/app/common/types/fills/impl.cljc +++ b/common/src/app/common/types/fills/impl.cljc @@ -301,11 +301,17 @@ IHeapWritable (-get-byte-size [_] - (- (.-byteLength dbuffer) 4)) + ;; Include the 4-byte header with the fill count + (+ 4 (* size FILL-U8-SIZE))) (-write-to [_ heap offset] - (let [buffer' (.-buffer ^js/DataView dbuffer)] - (.set heap (js/Uint32Array. buffer' 4) offset))) + (let [buffer' (.-buffer ^js/DataView dbuffer) + ;; Calculate byte size: 4 bytes header + (size * FILL-U8-SIZE) + byte-size (+ 4 (* size FILL-U8-SIZE)) + ;; Create Uint32Array with exact size needed (convert bytes to u32 elements) + u32-array (js/Uint32Array. buffer' 0 (/ byte-size 4))] + ;; Copy from offset 0 to include the header with fill count + (.set heap u32-array offset))) IBinaryFills (-get-image-ids [_] diff --git a/render-wasm/src/wasm/fills.rs b/render-wasm/src/wasm/fills.rs index 24935e7491..46901816e4 100644 --- a/render-wasm/src/wasm/fills.rs +++ b/render-wasm/src/wasm/fills.rs @@ -70,7 +70,10 @@ pub fn parse_fills_from_bytes(buffer: &[u8], num_fills: usize) -> Vec