From 613687e7361b1275b47196522a53dcdd2499f91b Mon Sep 17 00:00:00 2001 From: Ouwen Huang Date: Tue, 13 Jun 2023 23:09:47 -0400 Subject: [PATCH] fix: copy buffer to prevent oom in workers (#454) Large uncompressed multiframe data will send the full arraybuffer in a typed view. For large uncompressed data such as tomo these will result in OOM issues. This fix pre-slices the typed array view so only used buffer is sent via worker.postMessage. --- .../wadouri/getUncompressedImageFrame.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/imageLoader/wadouri/getUncompressedImageFrame.js b/src/imageLoader/wadouri/getUncompressedImageFrame.js index 683276b4..b28646ca 100644 --- a/src/imageLoader/wadouri/getUncompressedImageFrame.js +++ b/src/imageLoader/wadouri/getUncompressedImageFrame.js @@ -53,9 +53,7 @@ function getUncompressedImageFrame(dataSet, frameIndex) { } return new Uint8Array( - dataSet.byteArray.buffer, - frameOffset, - pixelsPerFrame + dataSet.byteArray.buffer.slice(frameOffset, frameOffset + pixelsPerFrame) ); } else if (bitsAllocated === 16) { frameOffset = pixelDataOffset + frameIndex * pixelsPerFrame * 2; @@ -64,9 +62,10 @@ function getUncompressedImageFrame(dataSet, frameIndex) { } return new Uint8Array( - dataSet.byteArray.buffer, - frameOffset, - pixelsPerFrame * 2 + dataSet.byteArray.buffer.slice( + frameOffset, + frameOffset + pixelsPerFrame * 2 + ) ); } else if (bitsAllocated === 1) { frameOffset = pixelDataOffset + frameIndex * pixelsPerFrame * 0.125; @@ -82,9 +81,10 @@ function getUncompressedImageFrame(dataSet, frameIndex) { } return new Uint8Array( - dataSet.byteArray.buffer, - frameOffset, - pixelsPerFrame * 4 + dataSet.byteArray.buffer.slice( + frameOffset, + frameOffset + pixelsPerFrame * 4 + ) ); }