Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sab): check for sab before using it #648

Merged
merged 6 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/dicomImageLoader/src/imageLoader/createImage.ts
Expand Up @@ -120,6 +120,13 @@ function createImage(
}
}

// we need to identify if the target buffer is a SharedArrayBuffer
// since inside the webworker we don't have access to the window
// to say if it is a SharedArrayBuffer or not with instanceof
options.isSharedArrayBuffer =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is still not correct. it should be...

  options.isSharedArrayBuffer =
    options.targetBuffer.arrayBuffer &&
    options.targetBuffer.arrayBuffer instanceof SharedArrayBuffer;

options.targetBuffer?.arrayBuffer &&
options.targetBuffer.arrayBuffer instanceof SharedArrayBuffer;

const { decodeConfig } = getOptions();
const decodePromise = decodeImageFrame(
imageFrame,
Expand Down
5 changes: 1 addition & 4 deletions packages/dicomImageLoader/src/shared/decodeImageFrame.ts
Expand Up @@ -261,11 +261,8 @@ function postProcessDecodedPixels(
// since we can't transfer ownership of a SharedArrayBuffer to another thread
// in the workers
const hasTargetBuffer = options.targetBuffer !== undefined;
const isNotSharedArrayBuffer =
hasTargetBuffer &&
!(options.targetBuffer.arrayBuffer instanceof SharedArrayBuffer);

if (!hasTargetBuffer || isNotSharedArrayBuffer) {
if (!hasTargetBuffer || !options.isSharedArrayBuffer) {
imageFrame.pixelData = pixelDataArray;
}

Expand Down
Expand Up @@ -14,5 +14,6 @@ export interface DICOMLoaderImageOptions {
length: number;
offset: number;
};
isSharedArrayBuffer?: boolean;
loader?: LoadRequestFunction;
}
3 changes: 2 additions & 1 deletion packages/docs/docusaurus.config.js
Expand Up @@ -172,8 +172,9 @@ module.exports = {
customCss: require.resolve('./src/css/custom.css'),
},
blog: false,
googleAnalytics: {
gtag: {
trackingID: 'G-LWTJVK40WP',
anonymizeIP: true,
},
},
],
Expand Down
1 change: 1 addition & 0 deletions packages/docs/package.json
Expand Up @@ -35,6 +35,7 @@
"@docusaurus/core": "2.3.1",
"@docusaurus/module-type-aliases": "2.3.1",
"@docusaurus/preset-classic": "2.3.1",
"@docusaurus/plugin-google-gtag": "2.3.1",
"@kitware/vtk.js": "27.3.1",
"@mdx-js/react": "^1.6.21",
"@svgr/webpack": "^6.2.1",
Expand Down