-
Notifications
You must be signed in to change notification settings - Fork 516
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
V2 : Issues with using JSON for serialization #502
Comments
@kaosat-dev this is unexpected behaviour. the small Float32Array values are being converted into objects. even the vec2/vec3 arrays are being converted to objects. |
JSON serializes simple arrays. So, one solution is to replace the Float32Array values with simple arrays. For example vec2.create() returns [0, 0] |
@z3dev I stumbled upon this problem when converting the web code to V2 and fixed it in some way (need to look it up): you are speaking about json.stringify(someJscadStuff) and not the weird old 'json serializer' right ? |
I believe that JSON.stringify() is making object strings, not arrays strings. |
I just read the specification for stringify(). It handles Arrays and typed arrays very different. Typed arrays are treated like objects, which enumerates across the attributes. UG |
Ugh indeed, so there are solutions (you can pass a function to stringify/parse to handle specific types, simple enough), but it is never going to be 'just' JSON.stringify |
then again @z3dev this is only needed when transfering data from the webWorker right ? (ie replace to/from compactBinary) |
Correct. Maybe we need the compact binary format again... did you add this to the list? |
yes and no |
With the move to arrays of Numbers, this is not longer an issue. Closing. |
Expected Behavior
Serialization of arrays is correct.
Actual Behavior
Arrays are being serialized as objects with "0" to "N" attributes.
{"sides":[[{"0":78.9363021850586,"1":-17.02008819580078},{"0":85.4400405883789,"1":0}],[{"0":85.4400405883789,"1":0},{"0":78.9363021850586,"1":17.02008819580078}],[{"0":78.9363021850586,"1":17.02008819580078},{"0":60.41522979736328,"1":31.449024200439453}],[{"0":60.41522979736328,"1":31.449024200439453},{"0":32.69648742675781,"1":41.09012985229492}],[{"0":32.69648742675781,"1":41.09012985229492},{"0":5.231693493002029e-15,"1":44.47563552856445}],[{"0":5.231693493002029e-15,"1":44.47563552856445},{"0":-32.69648742675781,"1":41.09012985229492}],[{"0":-32.69648742675781,"1":41.09012985229492},{"0":-60.41522979736328,"1":31.449024200439453}],[{"0":-60.41522979736328,"1":31.449024200439453},{"0":-78.9363021850586,"1":17.02008819580078}],[{"0":-78.9363021850586,"1":17.02008819580078},{"0":-85.4400405883789,"1":5.446694595454167e-15}],[{"0":-85.4400405883789,"1":5.446694595454167e-15},{"0":-78.9363021850586,"1":-17.02008819580078}],[{"0":-78.9363021850586,"1":-17.02008819580078},{"0":-60.41522979736328,"1":-31.449024200439453}],[{"0":-60.41522979736328,"1":-31.449024200439453},{"0":-32.69648742675781,"1":-41.09012985229492}],[{"0":-32.69648742675781,"1":-41.09012985229492},{"0":-1.5695080055489613e-14,"1":-44.47563552856445}],[{"0":-1.5695080055489613e-14,"1":-44.47563552856445},{"0":32.69648742675781,"1":-41.09012985229492}],[{"0":32.69648742675781,"1":-41.09012985229492},{"0":60.41522979736328,"1":-31.449024200439453}],[{"0":60.41522979736328,"1":-31.449024200439453},{"0":78.9363021850586,"1":-17.02008819580078}]],"transforms":{"0":0.3511234521865845,"1":-0.936329185962677,"2":0,"3":0,"4":0.936329185962677,"5":0.3511234521865845,"6":0,"7":0,"8":0,"9":0,"10":1,"11":0,"12":130,"13":180,"14":0,"15":1}}
The geom2.isA() and geom3.isA() functions are failing because the objects are being brought back with transforms being an object, not an array.
Steps to Reproduce the Problem
Specifications
The text was updated successfully, but these errors were encountered: