Skip to content

Commit 2d947af

Browse files
authored
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.
1 parent 093db67 commit 2d947af

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/imageLoader/wadouri/getUncompressedImageFrame.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ function getUncompressedImageFrame(dataSet, frameIndex) {
5353
}
5454

5555
return new Uint8Array(
56-
dataSet.byteArray.buffer,
57-
frameOffset,
58-
pixelsPerFrame
56+
dataSet.byteArray.buffer.slice(frameOffset, frameOffset + pixelsPerFrame)
5957
);
6058
} else if (bitsAllocated === 16) {
6159
frameOffset = pixelDataOffset + frameIndex * pixelsPerFrame * 2;
@@ -64,9 +62,10 @@ function getUncompressedImageFrame(dataSet, frameIndex) {
6462
}
6563

6664
return new Uint8Array(
67-
dataSet.byteArray.buffer,
68-
frameOffset,
69-
pixelsPerFrame * 2
65+
dataSet.byteArray.buffer.slice(
66+
frameOffset,
67+
frameOffset + pixelsPerFrame * 2
68+
)
7069
);
7170
} else if (bitsAllocated === 1) {
7271
frameOffset = pixelDataOffset + frameIndex * pixelsPerFrame * 0.125;
@@ -82,9 +81,10 @@ function getUncompressedImageFrame(dataSet, frameIndex) {
8281
}
8382

8483
return new Uint8Array(
85-
dataSet.byteArray.buffer,
86-
frameOffset,
87-
pixelsPerFrame * 4
84+
dataSet.byteArray.buffer.slice(
85+
frameOffset,
86+
frameOffset + pixelsPerFrame * 4
87+
)
8888
);
8989
}
9090

0 commit comments

Comments
 (0)