Skip to content

Commit

Permalink
fix(vtkdataarray): throw error if size in no multiple of numberOfComp…
Browse files Browse the repository at this point in the history
…onents
  • Loading branch information
bourdaisj authored and thewtex committed Nov 14, 2023
1 parent ab0829d commit 3cc3abb
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Sources/Common/Core/DataArray/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,12 @@ export function extend(publicAPI, model, initialValues = {}) {
macro.obj(publicAPI, model);
macro.set(publicAPI, model, ['name', 'numberOfComponents']);

if (model.size % model.numberOfComponents !== 0) {
throw new RangeError(
'model.size is not a multiple of model.numberOfComponents'
);
}

// Object specific methods
vtkDataArray(publicAPI, model);
}
Expand Down

8 comments on commit 3cc3abb

@Sergey1888888
Copy link

Choose a reason for hiding this comment

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

@bourdaisj @thewtex Hello, can someone please explain why this is needed?

@finetjul
Copy link
Member

Choose a reason for hiding this comment

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

I guess that simplify many checks (termination condition in for loops).

Why would you want to have an array size which is NOT a multiple of number of component ?

@Sergey1888888
Copy link

Choose a reason for hiding this comment

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

Honestly, I have no idea. But due to this check, some images are now not shown.

@finetjul
Copy link
Member

Choose a reason for hiding this comment

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

You might want to check the size/content/metadata of your images...

@Sergey1888888
Copy link

Choose a reason for hiding this comment

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

Ok, I'll check, thanks

@bourdaisj
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, if this condition happens to evaluate to true, there is likely a logical error somewhere in the library consumer code.
Without this check and throw statement, this error could be hard to spot.
I added those lines after fixing an error of this kind in a VTK.js example

@saumitra91
Copy link

Choose a reason for hiding this comment

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

How do I solve this error?
What property should I change in the dicom image for this error to be resolved?
Can anyone let me know please?

@bourdaisj
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @saumitra91
Sharing some data and/or code is a good first step to help us troubleshoot your problem.
If you think there is a bug in VTK.js, please open a new issue. If you need help, please consider opening a topic on the VTK discourse.

Please sign in to comment.