-
-
Notifications
You must be signed in to change notification settings - Fork 382
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 typed arrays serialization deserialization #2927
Fix typed arrays serialization deserialization #2927
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can think of 2 better (not orthogonal) alternatives:
vtkImageData.indexToWorld
andworldToIndex
must not be typed array but regular arrays, which are 64 bits anyway.vtkImageData.indexToWorld
andworldToIndex
shall not be serialized but must be flagged as protected by adding_
prefix and recomputed at deserialization.
to me those are not alternatives to the fix I'm proposing which is necessary but definitely you have a good point. |
I agree, your fix is also necessary. |
we actually uses |
The image direction matrices are a consequence of using gl-matrix for construction and allocation, since it defaults to Float32Arrays. I partially agree with @finetjul that the index/world transform matrices should be hidden from serialization, but having them is nice for downstream code to not have to always recompute the transforms upon deserialization (e.g. sending over the network). |
the behavior of JSON.stringify for typed arrays is to serialize them as objects with numeric keys. This cause crashes when re-building the object since it would try to fit an object where a typed array is required. This changes makes it so getState replaces typed arrays with plain javascript arrays.
fb62f4c
to
0ede1a2
Compare
Thanks for review and feedback guys! |
Let's leave it as is. |
🎉 This PR is included in version 28.12.4 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Context
The behavior of JSON.stringify for typed arrays is to serialize them as objects with numeric keys. This cause crashes when re-building the object since it would try to fit an object where a typed array is required. This changes makes it so getState replaces typed arrays with plain javascript arrays.
Typical example is
vtkImageData
direction property, which is by default Float64Arrayminimal reproduction:
see also Kitware/glance#480
Results
makes serialization/deserialization possible and successful
Changes
This change makes it so we serialize typed arrays as arrays.
PR and Code Checklist
npm run reformat
to have correctly formatted codeTesting