CesiumGS / CesiumGS/cesium

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

Open
#13,698 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
15.7k
Forks
3.9k
Avg merge
4d 6h
Merged PRs (30d)
34

Description

{
"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\n```javascript\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\n`TypeError: Cannot read properties of undefined (reading 'center')` thrown inside `Primitive.createVertexArray` at:\n```javascript\n// Cesium.js ~line 50246\nconst center = geometry.boundingSphereCV.center; // boundingSphereCV is undefined\n```\n\n## Root cause\n\nTwo functions drop `boundingSphereCV`:\n\n**1. `cloneGeometry` in PrimitivePipeline.js (~line 49550):** copies `boundingSphere` but not `boundingSphereCV`\n\n```javascript\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\n**2. `combineGeometries` in GeometryPipeline.js (~line 33773):** same issue\n\n```javascript\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`:**\n```javascript\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\n**`combineGeometries`:**\n```javascript\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"]
}

Contributor guide

Open the contributing guide

Research direction

Start in Source/Scene/PrimitivePipeline.js at cloneGeometry and Source/Core/GeometryPipeline.js at combineGeometries, then trace the Primitive.createVertexArray path described in the report. Verify that a FLOAT-position Geometry retaining boundingSphereCV can pass Primitive initialization and render without the reported TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.