automerge / automerge-classic

A JSON-like data structure (a CRDT) that can be modified concurrently by different users, and merged again automatically.
http://automerge.org/
MIT License
14.77k stars 467 forks source link

Uncaught TypeError: Unsupported type of value: undefined #504

Closed michaelpalumbo closed 1 year ago

michaelpalumbo commented 1 year ago

I'm working on an app that uses three.js, and am getting this error when attempting to the scene graph in automerge.

Uncaught TypeError: Unsupported type of value: undefined
    at Context.getValueDescription (context.js:53:13)
    at Context.setValue (context.js:302:32)
    at Context.createNestedObjects (context.js:268:33)
    at Context.setValue (context.js:299:19)
    at Context.insertListItems (context.js:400:33)
    at Context.createNestedObjects (context.js:258:12)
    at Context.setValue (context.js:299:19)
    at Context.createNestedObjects (context.js:268:33)
    at Context.setValue (context.js:299:19)
    at eval (context.js:342:33)

The code:

    let sceneJSON = scene.toJSON()
    doc1 = Automerge.change(doc1, 'update state', doc => {
        doc.three = sceneJSON
    })

The object I am trying to store:

{
    "metadata": {
        "version": 4.5,
        "type": "Object",
        "generator": "Object3D.toJSON"
    },
    "geometries": [
        {
            "uuid": "07c3cfcb-ea87-49cb-a098-7650fbf8fde5",
            "type": "BufferGeometry",
            "data": {
                "attributes": {
                    "position": {
                        "itemSize": 3,
                        "type": "Float32Array",
                        "array": [
                            0,
                            0,
                            0,
                            0,
                            -45,
                            -1
                        ],
                        "normalized": false
                    }
                },
                "boundingSphere": {
                    "center": [
                        0,
                        -22.5,
                        -0.5
                    ],
                    "radius": 22.5055548698538
                }
            }
        },
        {
            "uuid": "a500adb6-6124-4cc9-9c52-5111670b2f6b",
            "type": "BufferGeometry",
            "data": {
                "attributes": {
                    "position": {
                        "itemSize": 3,
                        "type": "Float32Array",
                        "array": [
                            0,
                            0,
                            0,
                            0,
                            -45,
                            -1
                        ],
                        "normalized": false
                    }
                },
                "boundingSphere": {
                    "center": [
                        0,
                        -22.5,
                        -0.5
                    ],
                    "radius": 22.5055548698538
                }
            }
        },
        {
            "uuid": "1909e2af-b59d-4baf-86d4-6903eb2b6f59",
            "type": "BoxGeometry",
            "width": 1,
            "height": 2,
            "depth": 0.3,
            "widthSegments": 1,
            "heightSegments": 1,
            "depthSegments": 1
        },
        {
            "uuid": "50869cf1-6436-4778-9edd-1f66177c7115",
            "type": "CylinderGeometry",
            "radiusTop": 0.2,
            "radiusBottom": 0.2,
            "height": 0.1,
            "radialSegments": 50,
            "heightSegments": 1,
            "openEnded": false,
            "thetaStart": 0,
            "thetaLength": 6.283185307179586
        },
        {
            "uuid": "902c4443-0890-42af-80ec-1daceb51e4f5",
            "type": "InstancedBufferGeometry",
            "data": {
                "attributes": {
                    "position": {
                        "itemSize": 3,
                        "type": "Float32Array",
                        "array": [
                            0,
                            1,
                            0,
                            1,
                            1,
                            0,
                            0,
                            0,
                            0,
                            1,
                            0,
                            0,
                            1,
                            1,
                            0,
                            0,
                            1,
                            0,
                            1,
                            0,
                            0,
                            0,
                            0,
                            0
                        ],
                        "normalized": false
                    },
                    "normal": {
                        "itemSize": 3,
                        "type": "Float32Array",
                        "array": [
                            0,
                            0,
                            1,
                            0,
                            0,
                            1,
                            0,
                            0,
                            1,
                            0,
                            0,
                            1,
                            0,
                            0,
                            -1,
                            0,
                            0,
                            -1,
                            0,
                            0,
                            -1,
                            0,
                            0,
                            -1
                        ],
                        "normalized": false
                    },
                    "uv": {
                        "itemSize": 2,
                        "type": "Float32Array",
                        "array": [
                            0,
                            1,
                            1,
                            1,
                            0,
                            0,
                            1,
                            0,
                            0,
                            1,
                            1,
                            1,
                            0,
                            0,
                            1,
                            0
                        ],
                        "normalized": false
                    }
                },
                "index": {
                    "type": "Uint16Array",
                    "array": [
                        0,
                        2,
                        1,
                        2,
                        3,
                        1,
                        4,
                        6,
                        5,
                        6,
                        7,
                        5
                    ]
                },
                "groups": [
                    {
                        "start": 0,
                        "count": null,
                        "materialIndex": 0
                    },
                    {
                        "start": 0,
                        "count": null,
                        "materialIndex": 1
                    }
                ],
                "boundingSphere": {
                    "center": [
                        0,
                        0,
                        0
                    ],
                    "radius": -1
                }
            },
            "instanceCount": null,
            "isInstancedBufferGeometry": true
        },
        {
            "uuid": "b2d84cee-edd8-42e0-b801-41b2893a5916",
            "type": "InstancedBufferGeometry",
            "data": {
                "attributes": {
                    "position": {
                        "itemSize": 3,
                        "type": "Float32Array",
                        "array": [
                            0,
                            1,
                            0,
                            1,
                            1,
                            0,
                            0,
                            0,
                            0,
                            1,
                            0,
                            0,
                            1,
                            1,
                            0,
                            0,
                            1,
                            0,
                            1,
                            0,
                            0,
                            0,
                            0,
                            0
                        ],
                        "normalized": false
                    },
                    "normal": {
                        "itemSize": 3,
                        "type": "Float32Array",
                        "array": [
                            0,
                            0,
                            1,
                            0,
                            0,
                            1,
                            0,
                            0,
                            1,
                            0,
                            0,
                            1,
                            0,
                            0,
                            -1,
                            0,
                            0,
                            -1,
                            0,
                            0,
                            -1,
                            0,
                            0,
                            -1
                        ],
                        "normalized": false
                    },
                    "uv": {
                        "itemSize": 2,
                        "type": "Float32Array",
                        "array": [
                            0,
                            1,
                            1,
                            1,
                            0,
                            0,
                            1,
                            0,
                            0,
                            1,
                            1,
                            1,
                            0,
                            0,
                            1,
                            0
                        ],
                        "normalized": false
                    }
                },
                "index": {
                    "type": "Uint16Array",
                    "array": [
                        0,
                        2,
                        1,
                        2,
                        3,
                        1,
                        4,
                        6,
                        5,
                        6,
                        7,
                        5
                    ]
                },
                "groups": [
                    {
                        "start": 0,
                        "count": null,
                        "materialIndex": 0
                    },
                    {
                        "start": 0,
                        "count": null,
                        "materialIndex": 1
                    }
                ],
                "boundingSphere": {
                    "center": [
                        0,
                        0,
                        0
                    ],
                    "radius": -1
                }
            },
            "instanceCount": null,
            "isInstancedBufferGeometry": true
        },
        {
            "uuid": "3412bcf6-003d-43d0-8088-66264f97eb5e",
            "type": "InstancedBufferGeometry",
            "data": {
                "attributes": {
                    "position": {
                        "itemSize": 3,
                        "type": "Float32Array",
                        "array": [
                            0,
                            1,
                            0,
                            1,
                            1,
                            0,
                            0,
                            0,
                            0,
                            1,
                            0,
                            0,
                            1,
                            1,
                            0,
                            0,
                            1,
                            0,
                            1,
                            0,
                            0,
                            0,
                            0,
                            0
                        ],
                        "normalized": false
                    },
                    "normal": {
                        "itemSize": 3,
                        "type": "Float32Array",
                        "array": [
                            0,
                            0,
                            1,
                            0,
                            0,
                            1,
                            0,
                            0,
                            1,
                            0,
                            0,
                            1,
                            0,
                            0,
                            -1,
                            0,
                            0,
                            -1,
                            0,
                            0,
                            -1,
                            0,
                            0,
                            -1
                        ],
                        "normalized": false
                    },
                    "uv": {
                        "itemSize": 2,
                        "type": "Float32Array",
                        "array": [
                            0,
                            1,
                            1,
                            1,
                            0,
                            0,
                            1,
                            0,
                            0,
                            1,
                            1,
                            1,
                            0,
                            0,
                            1,
                            0
                        ],
                        "normalized": false
                    }
                },
                "index": {
                    "type": "Uint16Array",
                    "array": [
                        0,
                        2,
                        1,
                        2,
                        3,
                        1,
                        4,
                        6,
                        5,
                        6,
                        7,
                        5
                    ]
                },
                "groups": [
                    {
                        "start": 0,
                        "count": null,
                        "materialIndex": 0
                    },
                    {
                        "start": 0,
                        "count": null,
                        "materialIndex": 1
                    }
                ],
                "boundingSphere": {
                    "center": [
                        0,
                        0,
                        0
                    ],
                    "radius": -1
                }
            },
            "instanceCount": null,
            "isInstancedBufferGeometry": true
        }
    ],
    "materials": [
        {
            "uuid": "909bf47d-ac6a-47ce-ae88-ebc48366984b",
            "type": "LineBasicMaterial",
            "color": 16777215,
            "depthFunc": 3,
            "depthTest": true,
            "depthWrite": true,
            "colorWrite": true,
            "stencilWrite": false,
            "stencilWriteMask": 255,
            "stencilFunc": 519,
            "stencilRef": 0,
            "stencilFuncMask": 255,
            "stencilFail": 7680,
            "stencilZFail": 7680,
            "stencilZPass": 7680,
            "linewidth": 20
        },
        {
            "uuid": "46bae959-0dc5-44b5-a7bc-c69f58d23e06",
            "type": "LineBasicMaterial",
            "color": 16777215,
            "depthFunc": 3,
            "depthTest": true,
            "depthWrite": true,
            "colorWrite": true,
            "stencilWrite": false,
            "stencilWriteMask": 255,
            "stencilFunc": 519,
            "stencilRef": 0,
            "stencilFuncMask": 255,
            "stencilFail": 7680,
            "stencilZFail": 7680,
            "stencilZPass": 7680,
            "linewidth": 20
        },
        {
            "uuid": "500b2581-54b1-4161-ac33-0336ab848002",
            "type": "MeshStandardMaterial",
            "color": 11674146,
            "roughness": 1,
            "metalness": 0,
            "emissive": 0,
            "envMapIntensity": 1,
            "depthFunc": 3,
            "depthTest": true,
            "depthWrite": true,
            "colorWrite": true,
            "stencilWrite": false,
            "stencilWriteMask": 255,
            "stencilFunc": 519,
            "stencilRef": 0,
            "stencilFuncMask": 255,
            "stencilFail": 7680,
            "stencilZFail": 7680,
            "stencilZPass": 7680,
            "flatShading": true
        },
        {
            "uuid": "fb121278-e665-42d1-84e5-dc2b97421fb6",
            "type": "MeshStandardMaterial",
            "color": 3100495,
            "roughness": 1,
            "metalness": 0,
            "emissive": 0,
            "envMapIntensity": 1,
            "depthFunc": 3,
            "depthTest": true,
            "depthWrite": true,
            "colorWrite": true,
            "stencilWrite": false,
            "stencilWriteMask": 255,
            "stencilFunc": 519,
            "stencilRef": 0,
            "stencilFuncMask": 255,
            "stencilFail": 7680,
            "stencilZFail": 7680,
            "stencilZPass": 7680,
            "flatShading": true
        },
        {
            "uuid": "79AEF343-2F1D-49D6-B947-37099BD6FC92",
            "type": "MeshBasicMaterial",
            "color": 16777215,
            "reflectivity": 1,
            "refractionRatio": 0.98,
            "shadowSide": 2,
            "side": 2,
            "transparent": true,
            "depthFunc": 3,
            "depthTest": true,
            "depthWrite": true,
            "colorWrite": true,
            "stencilWrite": false,
            "stencilWriteMask": 255,
            "stencilFunc": 519,
            "stencilRef": 0,
            "stencilFuncMask": 255,
            "stencilFail": 7680,
            "stencilZFail": 7680,
            "stencilZPass": 7680
        },
        {
            "uuid": "7963A9EA-4D0D-4A9C-9F8D-F3C6E076AF2A",
            "type": "MeshBasicMaterial",
            "color": 16777215,
            "reflectivity": 1,
            "refractionRatio": 0.98,
            "shadowSide": 2,
            "side": 2,
            "transparent": true,
            "depthFunc": 3,
            "depthTest": true,
            "depthWrite": true,
            "colorWrite": true,
            "stencilWrite": false,
            "stencilWriteMask": 255,
            "stencilFunc": 519,
            "stencilRef": 0,
            "stencilFuncMask": 255,
            "stencilFail": 7680,
            "stencilZFail": 7680,
            "stencilZPass": 7680
        },
        {
            "uuid": "21b87324-db9e-4648-a0ce-115c9d38215a",
            "type": "MeshStandardMaterial",
            "color": 8900331,
            "roughness": 1,
            "metalness": 0,
            "emissive": 0,
            "envMapIntensity": 1,
            "depthFunc": 3,
            "depthTest": true,
            "depthWrite": true,
            "colorWrite": true,
            "stencilWrite": false,
            "stencilWriteMask": 255,
            "stencilFunc": 519,
            "stencilRef": 0,
            "stencilFuncMask": 255,
            "stencilFail": 7680,
            "stencilZFail": 7680,
            "stencilZPass": 7680,
            "flatShading": true
        },
        {
            "uuid": "8C00DC42-0B0F-4BA3-A6C3-7772BFADA50E",
            "type": "MeshBasicMaterial",
            "color": 16777215,
            "reflectivity": 1,
            "refractionRatio": 0.98,
            "shadowSide": 2,
            "side": 2,
            "transparent": true,
            "depthFunc": 3,
            "depthTest": true,
            "depthWrite": true,
            "colorWrite": true,
            "stencilWrite": false,
            "stencilWriteMask": 255,
            "stencilFunc": 519,
            "stencilRef": 0,
            "stencilFuncMask": 255,
            "stencilFail": 7680,
            "stencilZFail": 7680,
            "stencilZPass": 7680
        }
    ],
    "object": {
        "uuid": "9f53afa2-b575-436c-941d-8e041dee3066",
        "type": "Scene",
        "layers": 1,
        "matrix": [
            1,
            0,
            0,
            0,
            0,
            1,
            0,
            0,
            0,
            0,
            1,
            0,
            0,
            0,
            0,
            1
        ],
        "background": 0,
        "children": [
            {
                "uuid": "91b209d5-cc16-4cce-ab51-3c8d3b5361dd",
                "type": "Group",
                "visible": false,
                "layers": 1,
                "matrix": [
                    1,
                    0,
                    0,
                    0,
                    0,
                    1,
                    0,
                    0,
                    0,
                    0,
                    1,
                    0,
                    0,
                    0,
                    0,
                    1
                ],
                "matrixAutoUpdate": false,
                "children": [
                    {
                        "uuid": "8d0f1e97-af82-451d-81f8-4baaf3d90f4e",
                        "type": "Object3D",
                        "layers": 1,
                        "matrix": [
                            1,
                            0,
                            0,
                            0,
                            0,
                            1,
                            0,
                            0,
                            0,
                            0,
                            1,
                            0,
                            0,
                            0,
                            0,
                            1
                        ]
                    },
                    {
                        "uuid": "72b5fa36-9cf5-46b3-ad55-595350f53948",
                        "type": "Line",
                        "name": "xrControllerRaycastBeam",
                        "layers": 1,
                        "matrix": [
                            1,
                            0,
                            0,
                            0,
                            0,
                            1,
                            0,
                            0,
                            0,
                            0,
                            100,
                            0,
                            0,
                            0,
                            0,
                            1
                        ],
                        "geometry": "07c3cfcb-ea87-49cb-a098-7650fbf8fde5",
                        "material": "909bf47d-ac6a-47ce-ae88-ebc48366984b"
                    }
                ]
            },
            {
                "uuid": "212736ff-2b05-4b71-b198-4dd63a43913a",
                "type": "Group",
                "visible": false,
                "layers": 1,
                "matrix": [
                    1,
                    0,
                    0,
                    0,
                    0,
                    1,
                    0,
                    0,
                    0,
                    0,
                    1,
                    0,
                    0,
                    0,
                    0,
                    1
                ],
                "matrixAutoUpdate": false,
                "children": [
                    {
                        "uuid": "ee8f561b-9fae-446e-bea8-0e6a4479a1a6",
                        "type": "Object3D",
                        "layers": 1,
                        "matrix": [
                            1,
                            0,
                            0,
                            0,
                            0,
                            1,
                            0,
                            0,
                            0,
                            0,
                            1,
                            0,
                            0,
                            0,
                            0,
                            1
                        ]
                    },
                    {
                        "uuid": "87e3555a-d0a3-4eb4-86cb-106dd84d8e35",
                        "type": "Line",
                        "name": "xrControllerRaycastBeam",
                        "layers": 1,
                        "matrix": [
                            1,
                            0,
                            0,
                            0,
                            0,
                            1,
                            0,
                            0,
                            0,
                            0,
                            100,
                            0,
                            0,
                            0,
                            0,
                            1
                        ],
                        "geometry": "a500adb6-6124-4cc9-9c52-5111670b2f6b",
                        "material": "46bae959-0dc5-44b5-a7bc-c69f58d23e06"
                    }
                ]
            },
            {
                "uuid": "4c172b6a-f862-46b0-92b9-4413d9e1c94f",
                "type": "HemisphereLight",
                "layers": 1,
                "matrix": [
                    1,
                    0,
                    0,
                    0,
                    0,
                    1,
                    0,
                    0,
                    0,
                    0,
                    1,
                    0,
                    0,
                    1,
                    0,
                    1
                ],
                "color": 16777215,
                "intensity": 3,
                "groundColor": 3100495
            },
            {
                "uuid": "8d07659a-d75f-433e-ba50-bdd95a6482ca",
                "type": "DirectionalLight",
                "layers": 1,
                "matrix": [
                    1,
                    0,
                    0,
                    0,
                    0,
                    1,
                    0,
                    0,
                    0,
                    0,
                    1,
                    0,
                    10,
                    10,
                    10,
                    1
                ],
                "color": 16777215,
                "intensity": 8,
                "shadow": {
                    "camera": {
                        "uuid": "cad890a4-2c69-4111-badf-5f285218d210",
                        "type": "OrthographicCamera",
                        "layers": 1,
                        "zoom": 1,
                        "left": -5,
                        "right": 5,
                        "top": 5,
                        "bottom": -5,
                        "near": 0.5,
                        "far": 500
                    }
                }
            },
            {
                "uuid": "47d4721b-509e-4723-a86a-fa2c33e8ab16",
                "type": "Group",
                "name": "abs",
                "layers": 1,
                "matrix": [
                    1,
                    0,
                    0,
                    0,
                    0,
                    1,
                    0,
                    0,
                    0,
                    0,
                    1,
                    0,
                    0,
                    0,
                    0,
                    1
                ],
                "children": [
                    {
                        "uuid": "abb41b39-f02b-4983-8fa3-6b7219eb237c",
                        "type": "Mesh",
                        "name": "panel_abs_abb41b39-f02b-4983-8fa3-6b7219eb237c",
                        "layers": 1,
                        "matrix": [
                            1,
                            0,
                            0,
                            0,
                            0,
                            1,
                            0,
                            0,
                            0,
                            0,
                            1,
                            0,
                            0,
                            0,
                            0,
                            1
                        ],
                        "geometry": "1909e2af-b59d-4baf-86d4-6903eb2b6f59",
                        "material": "500b2581-54b1-4161-ac33-0336ab848002"
                    },
                    {
                        "uuid": "b0e40356-073d-40ae-b60c-b7e34a896be8",
                        "type": "Mesh",
                        "name": "outlet_abs_b0e40356-073d-40ae-b60c-b7e34a896be8",
                        "layers": 1,
                        "matrix": [
                            1,
                            0,
                            0,
                            0,
                            0,
                            1,
                            0,
                            0,
                            0,
                            0,
                            1,
                            0,
                            0,
                            0,
                            0,
                            1
                        ],
                        "geometry": "50869cf1-6436-4778-9edd-1f66177c7115",
                        "material": "fb121278-e665-42d1-84e5-dc2b97421fb6"
                    },
                    {
                        "uuid": "7b7ae967-7769-4a29-8051-f0ce3c95c679",
                        "type": "Mesh",
                        "layers": 1,
                        "matrix": [
                            1,
                            0,
                            0,
                            0,
                            0,
                            1,
                            0,
                            0,
                            0,
                            0,
                            1,
                            0,
                            0,
                            0,
                            0,
                            1
                        ],
                        "geometry": "902c4443-0890-42af-80ec-1daceb51e4f5",
                        "material": "79AEF343-2F1D-49D6-B947-37099BD6FC92"
                    },
                    {
                        "uuid": "e2fc8fd5-6a6a-48f6-8ec5-5d8495a0b138",
                        "type": "Mesh",
                        "layers": 1,
                        "matrix": [
                            1,
                            0,
                            0,
                            0,
                            0,
                            1,
                            0,
                            0,
                            0,
                            0,
                            1,
                            0,
                            0,
                            0,
                            0,
                            1
                        ],
                        "geometry": "b2d84cee-edd8-42e0-b801-41b2893a5916",
                        "material": "7963A9EA-4D0D-4A9C-9F8D-F3C6E076AF2A"
                    },
                    {
                        "uuid": "6a3e28cc-ff10-472b-9bf5-fb4a8ee786a6",
                        "type": "Mesh",
                        "name": "inlet_value_6a3e28cc-ff10-472b-9bf5-fb4a8ee786a6",
                        "layers": 1,
                        "matrix": [
                            1,
                            0,
                            0,
                            0,
                            0,
                            1,
                            0,
                            0,
                            0,
                            0,
                            1,
                            0,
                            0,
                            0,
                            0,
                            1
                        ],
                        "geometry": "50869cf1-6436-4778-9edd-1f66177c7115",
                        "material": "21b87324-db9e-4648-a0ce-115c9d38215a"
                    },
                    {
                        "uuid": "bf7c6627-1d96-4477-8fe3-35f8a8da35db",
                        "type": "Mesh",
                        "layers": 1,
                        "matrix": [
                            1,
                            0,
                            0,
                            0,
                            0,
                            1,
                            0,
                            0,
                            0,
                            0,
                            1,
                            0,
                            0,
                            0,
                            0,
                            1
                        ],
                        "geometry": "3412bcf6-003d-43d0-8088-66264f97eb5e",
                        "material": "8C00DC42-0B0F-4BA3-A6C3-7772BFADA50E"
                    }
                ]
            }
        ]
    }
}
ept commented 1 year ago

Hi @michaelpalumbo, I tried running the code with your JSON and it worked fine for me. The error message indicates that you have an undefined value somewhere in your data, which is not supported by Automerge (because most languages other than JS don't have the distinction between null and undefined, and Automerge needs to support multiple languages). You'll need to find where the undefined value is being used, and replace it with null.

michaelpalumbo commented 1 year ago

hmm. ok. i'll try to track that down! thanks @ept

michaelpalumbo commented 1 year ago

@ept In the meantime, I'm able to get it working if I stringify the object before passing to automerge. it strikes me as maybe not using automerge to its strengths, operating on a very large string instead of an object, but do you foresee any problem with doing that?

michaelpalumbo commented 1 year ago

for anyone also using threeJS, I've started this thread in their forums about this problem I'm having

ept commented 1 year ago

@michaelpalumbo If you stringify the whole object, you might as well not use Automerge at all because you won't get any of its merging behaviour. If two users update the data concurrently, you will simply get a conflict between the two JSON strings that you would have to resolve manually.

Hope you can get it working. I'm going to close this issue since it's not an issue with Automerge itself.

michaelpalumbo commented 1 year ago

Thanks Martin. Yes, and we've decided to cherry pick the data from the threeJS scene object so that we can avoid this problem anyway. take care!

On Tue, Aug 30, 2022 at 12:27 PM Martin Kleppmann @.***> wrote:

Closed #504 https://github.com/automerge/automerge/issues/504 as completed.

— Reply to this email directly, view it on GitHub https://github.com/automerge/automerge/issues/504#event-7289191077, or unsubscribe https://github.com/notifications/unsubscribe-auth/AASLT4IKWQHEITILIVVOYTDV3YY6VANCNFSM56BLPJFQ . You are receiving this because you were mentioned.Message ID: @.***>

--

https://linktr.ee/thispatcher -- all things me https://linkr.ee/exitpoints -- exit points concert series