Просмотр исходного кода

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>
AlexRynas 7 месяцев назад
Родитель
Сommit
4f67fd3767
1 измененных файлов с 10 добавлено и 3 удалено
  1. 10 3
      editor/js/Viewport.Info.js

+ 10 - 3
editor/js/Viewport.Info.js

@@ -60,8 +60,15 @@ function ViewportInfo( editor ) {
 				if ( object.isMesh || object.isPoints ) {
 
 					const geometry = object.geometry;
+					const positionAttribute = geometry.attributes.position;
 
-					vertices += geometry.attributes.position.count;
+					// update counts only if vertex data are defined
+
+					if ( positionAttribute !== undefined && positionAttribute !== null ) {
+
+						vertices += positionAttribute.count;
+
+					}
 
 					if ( object.isMesh ) {
 
@@ -69,9 +76,9 @@ function ViewportInfo( editor ) {
 
 							triangles += geometry.index.count / 3;
 
-						} else {
+						} else if ( positionAttribute !== undefined && positionAttribute !== null ) {
 
-							triangles += geometry.attributes.position.count / 3;
+							triangles += positionAttribute.count / 3;
 
 						}
 

粤ICP备19079148号