Skip to content

Commit 4f67fd3

Browse files
AlexRynasMugen87
andauthored
Editor: Fix crash when geometry lacks position attribute. (#31334)
* Fix crash when geometry lacks position attribute in Viewport.Info This patch prevents a runtime error in Viewport.Info.js that occurs when importing a GLB file containing geometries without a position attribute. Previously, the code assumed all geometries had a position, leading to: Viewport.Info.js:64 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'count') at Viewport.Info.js:64:47 at Mesh.traverseVisible (three.core.js:14211:3) at Object3D.traverseVisible (three.core.js:14217:18) at Group.traverseVisible (three.core.js:14217:18) at update (Viewport.Info.js:56:11) at h.execute (signals.min.js:9:20) at e.dispatch (signals.min.js:13:106) at e.dispatch (signals.min.js:8:368) at Editor.addObject (Editor.js:194:28) at AddObjectCommand.execute (AddObjectCommand.js:29:15) Such cases are valid in glTF and occur with point clouds, line geometries, or custom data-only meshes. Fixes included: Introduced a null check before accessing geometry.attributes.position. Ensured vertex and triangle counts are calculated only if position is defined. Used a local positionAttr variable consistently to avoid repeated access. This change improves Editor robustness by allowing valid, non-standard GLB files to load without crashing, and maintains accurate scene statistics when available. * Update Viewport.Info.js --------- Co-authored-by: Michael Herzog <michael.herzog@human-interactive.org>
1 parent e9277b2 commit 4f67fd3

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

editor/js/Viewport.Info.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,25 @@ function ViewportInfo( editor ) {
6060
if ( object.isMesh || object.isPoints ) {
6161

6262
const geometry = object.geometry;
63+
const positionAttribute = geometry.attributes.position;
6364

64-
vertices += geometry.attributes.position.count;
65+
// update counts only if vertex data are defined
66+
67+
if ( positionAttribute !== undefined && positionAttribute !== null ) {
68+
69+
vertices += positionAttribute.count;
70+
71+
}
6572

6673
if ( object.isMesh ) {
6774

6875
if ( geometry.index !== null ) {
6976

7077
triangles += geometry.index.count / 3;
7178

72-
} else {
79+
} else if ( positionAttribute !== undefined && positionAttribute !== null ) {
7380

74-
triangles += geometry.attributes.position.count / 3;
81+
triangles += positionAttribute.count / 3;
7582

7683
}
7784

0 commit comments

Comments
 (0)