Skip to content

Bug: boundingSphereCV lost after cloneGeometry/combineGeometries, causes TypeError in createVertexArray #13698

Description

@jiakunpeng-1

{
"title": "Bug: boundingSphereCV lost after cloneGeometry/combineGeometries, causes TypeError in createVertexArray",
"body": "## Describe the bug\n\nWhen creating a Cesium.Geometry with FLOAT position attributes and setting both boundingSphere and boundingSphereCV, the boundingSphereCV is silently dropped during the Primitive initialization pipeline, causing a TypeError: Cannot read properties of undefined (reading 'center') at runtime.\n\n## Steps to reproduce\n\njavascript\nconst geometry = new Cesium.Geometry({\n attributes: {\n position: new Cesium.GeometryAttribute({\n componentDatatype: Cesium.ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: vertices,\n }),\n normal: new Cesium.GeometryAttribute({\n componentDatatype: Cesium.ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: normals,\n }),\n st: new Cesium.GeometryAttribute({\n componentDatatype: Cesium.ComponentDatatype.FLOAT,\n componentsPerAttribute: 2,\n values: uvs,\n }),\n },\n indices: indices,\n primitiveType: Cesium.PrimitiveType.TRIANGLES,\n boundingSphere: Cesium.BoundingSphere.fromVertices(vertices),\n boundingSphereCV: Cesium.BoundingSphere.fromVertices(vertices),\n vertexFormat: new Cesium.VertexFormat({\n position: true,\n normal: true,\n st: true,\n }),\n});\n\nconst primitive = new Cesium.Primitive({\n geometryInstances: new Cesium.GeometryInstance({ geometry }),\n appearance: new Cesium.MaterialAppearance({\n material: Cesium.Material.fromType('Color', { color: Cesium.Color.RED }),\n }),\n asynchronous: false,\n});\n\nviewer.scene.primitives.add(primitive);\n\n\n## Expected behavior\n\nThe primitive renders without error.\n\n## Actual behavior\n\nTypeError: Cannot read properties of undefined (reading 'center') thrown inside Primitive.createVertexArray at:\njavascript\n// Cesium.js ~line 50246\nconst center = geometry.boundingSphereCV.center; // boundingSphereCV is undefined\n\n\n## Root cause\n\nTwo functions drop boundingSphereCV:\n\n1. cloneGeometry in PrimitivePipeline.js (~line 49550): copies boundingSphere but not boundingSphereCV\n\njavascript\nreturn new Geometry_default({\n attributes: newAttributes,\n indices,\n primitiveType: geometry.primitiveType,\n boundingSphere: BoundingSphere_default.clone(geometry.boundingSphere)\n // missing: boundingSphereCV\n});\n\n\n2. combineGeometries in GeometryPipeline.js (~line 33773): same issue\n\njavascript\nreturn new Geometry_default({\n attributes,\n indices,\n primitiveType,\n boundingSphere: defined_default(center) ? new BoundingSphere_default(center, radius) : void 0\n // missing: boundingSphereCV\n});\n\n\nSince projectTo2D only sets boundingSphereCV when componentDatatype === DOUBLE, the FLOAT path relies entirely on the caller's pre-set value, which gets stripped by the clone/combine pipeline.\n\n## Proposed fix\n\nAdd boundingSphereCV to both return statements:\n\n**cloneGeometry:\njavascript\nreturn new Geometry_default({\n attributes: newAttributes,\n indices,\n primitiveType: geometry.primitiveType,\n boundingSphere: BoundingSphere_default.clone(geometry.boundingSphere),\n boundingSphereCV: geometry.boundingSphereCV\n ? BoundingSphere_default.clone(geometry.boundingSphereCV)\n : undefined\n});\n\n\ncombineGeometries:**\njavascript\nreturn new Geometry_default({\n attributes,\n indices,\n primitiveType,\n boundingSphere: defined_default(center) ? new BoundingSphere_default(center, radius) : void 0,\n boundingSphereCV: geometry.boundingSphereCV\n ? BoundingSphere_default.clone(geometry.boundingSphereCV)\n : undefined\n});\n\n",
"labels": ["bug"]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions