Python exception while importing glb #91217

Closed
opened 2021-09-06 14:10:25 +02:00 by Julien · 19 comments

System Information
Operating system: Windows-10-10.0.19041-SP0 64 Bits
Graphics card: GeForce GTX 970/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 456.71

Blender Version
Broken: version: 2.93.1, branch: master, commit date: 2021-06-22 05:57, hash: blender/blender@1b8d33b18c
Worked: unknown (not 2.82)

Short description of error
Here is the stacktrace:

Data are loaded, start creating Blender stuff
Python: Traceback (most recent call last):
  File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\addons\io_scene_gltf2\__init__.py", line 1050, in execute
    return self.import_gltf2(context)
  File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\addons\io_scene_gltf2\__init__.py", line 1064, in import_gltf2
    if self.unit_import(path, import_settings) == {'FINISHED'}:
  File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\addons\io_scene_gltf2\__init__.py", line 1084, in unit_import
    BlenderGlTF.create(gltf_importer)
  File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\addons\io_scene_gltf2\blender\imp\gltf2_blender_gltf.py", line 42, in create
    BlenderGlTF._create(gltf)
  File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\addons\io_scene_gltf2\blender\imp\gltf2_blender_gltf.py", line 49, in _create
    BlenderScene.create(gltf)
  File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\addons\io_scene_gltf2\blender\imp\gltf2_blender_scene.py", line 40, in create
    BlenderNode.create_vnode(gltf, 'root')
  File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\addons\io_scene_gltf2\blender\imp\gltf2_blender_node.py", line 51, in create_vnode
    BlenderNode.create_vnode(gltf, child)
  File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\addons\io_scene_gltf2\blender\imp\gltf2_blender_node.py", line 51, in create_vnode
    BlenderNode.create_vnode(gltf, child)
  File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\addons\io_scene_gltf2\blender\imp\gltf2_blender_node.py", line 38, in create_vnode
    BlenderNode.create_object(gltf, vnode_id)
  File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\addons\io_scene_gltf2\blender\imp\gltf2_blender_node.py", line 58, in create_object
    obj = BlenderNode.create_mesh_object(gltf, vnode)
  File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\addons\io_scene_gltf2\blender\imp\gltf2_blender_node.py", line 187, in create_mesh_object
    pymesh = gltf.data.meshes[pynode.mesh]
IndexError: list index out of range

location: <unknown location>:-1

Exact steps for others to reproduce the error
Unfortunatly, I can not provide the file I tried to import.

**System Information** Operating system: Windows-10-10.0.19041-SP0 64 Bits Graphics card: GeForce GTX 970/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 456.71 **Blender Version** Broken: version: 2.93.1, branch: master, commit date: 2021-06-22 05:57, hash: `blender/blender@1b8d33b18c` Worked: unknown (not 2.82) **Short description of error** Here is the stacktrace: ``` Data are loaded, start creating Blender stuff Python: Traceback (most recent call last): File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\addons\io_scene_gltf2\__init__.py", line 1050, in execute return self.import_gltf2(context) File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\addons\io_scene_gltf2\__init__.py", line 1064, in import_gltf2 if self.unit_import(path, import_settings) == {'FINISHED'}: File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\addons\io_scene_gltf2\__init__.py", line 1084, in unit_import BlenderGlTF.create(gltf_importer) File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\addons\io_scene_gltf2\blender\imp\gltf2_blender_gltf.py", line 42, in create BlenderGlTF._create(gltf) File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\addons\io_scene_gltf2\blender\imp\gltf2_blender_gltf.py", line 49, in _create BlenderScene.create(gltf) File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\addons\io_scene_gltf2\blender\imp\gltf2_blender_scene.py", line 40, in create BlenderNode.create_vnode(gltf, 'root') File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\addons\io_scene_gltf2\blender\imp\gltf2_blender_node.py", line 51, in create_vnode BlenderNode.create_vnode(gltf, child) File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\addons\io_scene_gltf2\blender\imp\gltf2_blender_node.py", line 51, in create_vnode BlenderNode.create_vnode(gltf, child) File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\addons\io_scene_gltf2\blender\imp\gltf2_blender_node.py", line 38, in create_vnode BlenderNode.create_object(gltf, vnode_id) File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\addons\io_scene_gltf2\blender\imp\gltf2_blender_node.py", line 58, in create_object obj = BlenderNode.create_mesh_object(gltf, vnode) File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\addons\io_scene_gltf2\blender\imp\gltf2_blender_node.py", line 187, in create_mesh_object pymesh = gltf.data.meshes[pynode.mesh] IndexError: list index out of range location: <unknown location>:-1 ``` **Exact steps for others to reproduce the error** Unfortunatly, I can not provide the file I tried to import.
Author

Added subscriber: @Ping

Added subscriber: @Ping

Added subscriber: @scurest

Added subscriber: @scurest

The .glb might be invalid. Try it in one of these.

glTF Validator: https://github.khronos.org/glTF-Validator/
glTF Viewer: https://gltf-viewer.donmccurdy.com/

The .glb might be invalid. Try it in one of these. glTF Validator: https://github.khronos.org/glTF-Validator/ glTF Viewer: https://gltf-viewer.donmccurdy.com/
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

Changed status from 'Needs Triage' to: 'Needs User Info'

Changed status from 'Needs Triage' to: 'Needs User Info'
Member

Unfortunatly, I can not provide the file I tried to import

Without this, it is very unlikely this will be reproduced.
Will set to Needs Information from User until some sharable .glb can be provided that show this issue.

> Unfortunatly, I can not provide the file I tried to import Without this, it is very unlikely this will be reproduced. Will set to Needs Information from User until some sharable .glb can be provided that show this issue.
Author

Ok, I have Unresolved references in the file. Isn't it possible to ignore those references in the importer ?

Ok, I have Unresolved references in the file. Isn't it possible to ignore those references in the importer ?
Member

In #91217#1216706, @Ping wrote:
Ok, I have Unresolved references in the file. Isn't it possible to ignore those references in the importer ?

Think so, could you still share a minimal example .blend (or multiple if neccessary -- references are linked libraries here?)?

> In #91217#1216706, @Ping wrote: > Ok, I have Unresolved references in the file. Isn't it possible to ignore those references in the importer ? Think so, could you still share a minimal example .blend (or multiple if neccessary -- references are linked libraries here?)?

@lichtwerk "Unresolved reference" is the error the glTF validator gives for invalid glTF files that do stuff like this

  // JSON data inside the .glb...
  "meshes" : [
      { ... }, // mesh 0
      { ... }, // mesh 1
      { ... }, // mesh 2
  ],
  "nodes" : [
      {
          "mesh" : 3, // there is no mesh 3! UNRESOLVED_REFERENCE
      }
  ]

This is a bug in the software the created the .glb.

@lichtwerk "Unresolved reference" is the error the glTF validator gives for invalid glTF files that do stuff like this ``` // JSON data inside the .glb... "meshes" : [ { ... }, // mesh 0 { ... }, // mesh 1 { ... }, // mesh 2 ], "nodes" : [ { "mesh" : 3, // there is no mesh 3! UNRESOLVED_REFERENCE } ] ``` This is a bug in the software the created the .glb.
Author

Yes, this is exactly the problem (in a glb file not in json but the problem is the same) but I don't need the unresolved meshes and it will be great to get the file opened by discarding those parts. I can try to produce a file having this problem to submit it but it probably will be easier for me to provide a patch of the code.

Yes, this is exactly the problem (in a glb file not in json but the problem is the same) but I don't need the unresolved meshes and it will be great to get the file opened by discarding those parts. I can try to produce a file having this problem to submit it but it probably will be easier for me to provide a patch of the code.

I don't think the importer should try to handle this, whatever program produced the .glb should get fixed instead.

@Ping You can probably throw this quick hack onto it to get this one .glb file to work if you want to though.

diff --git a/addons/io_scene_gltf2/blender/imp/gltf2_blender_node.py b/addons/io_scene_gltf2/blender/imp/gltf2_blender_node.py
index 041bf1eb..867ec367 100644
--- a/addons/io_scene_gltf2/blender/imp/gltf2_blender_node.py
+++ b/addons/io_scene_gltf2/blender/imp/gltf2_blender_node.py
@@ -184,6 +184,8 @@ class BlenderNode():
     @staticmethod
     def create_mesh_object(gltf, vnode):
         pynode = gltf.data.nodes[vnode.mesh_node_idx]
+        if not (0 <= pynode.mesh < len(gltf.data.meshes)):
+            return bpy.data.objects.new(vnode.name or mesh.name, None)
         pymesh = gltf.data.meshes[pynode.mesh]
 
         # Key to cache the Blender mesh by.
I don't think the importer should try to handle this, whatever program produced the .glb should get fixed instead. @Ping You can probably throw this quick hack onto it to get this one .glb file to work if you want to though. ``` diff --git a/addons/io_scene_gltf2/blender/imp/gltf2_blender_node.py b/addons/io_scene_gltf2/blender/imp/gltf2_blender_node.py index 041bf1eb..867ec367 100644 --- a/addons/io_scene_gltf2/blender/imp/gltf2_blender_node.py +++ b/addons/io_scene_gltf2/blender/imp/gltf2_blender_node.py @@ -184,6 +184,8 @@ class BlenderNode(): @staticmethod def create_mesh_object(gltf, vnode): pynode = gltf.data.nodes[vnode.mesh_node_idx] + if not (0 <= pynode.mesh < len(gltf.data.meshes)): + return bpy.data.objects.new(vnode.name or mesh.name, None) pymesh = gltf.data.meshes[pynode.mesh] # Key to cache the Blender mesh by. ```
Member

Changed status from 'Needs User Info' to: 'Needs Developer To Reproduce'

Changed status from 'Needs User Info' to: 'Needs Developer To Reproduce'
Member

Added subscriber: @JulienDuroure

Added subscriber: @JulienDuroure
Member

Thx for the info reg. Unresolved Reference.

I don't think the importer should try to handle this, whatever program produced the .glb should get fixed instead.

True, sometimes it might make sense to handle this more gracefully though (see recent 4e30cfd306})

Will leave up to @JulienDuroure to decide.

Thx for the info reg. Unresolved Reference. > I don't think the importer should try to handle this, whatever program produced the .glb should get fixed instead. True, sometimes it might make sense to handle this more gracefully though (see recent 4e30cfd306}) Will leave up to @JulienDuroure to decide.
Author

@scurest (scurest) Thanks a not.
But I still think it's a good choice for a sofware to get rid of errors in user inputs if possible rather than only show a stacktrace.
Thanks again

@scurest (scurest) Thanks a not. But I still think it's a good choice for a sofware to get rid of errors in user inputs if possible rather than only show a stacktrace. Thanks again
Member

I agree that importer can't handle all errors raised by invalid file.
But because there is, for this particular issue, a quick check that can be performed to avoid traceback, it is worth adding it

I agree that importer can't handle all errors raised by invalid file. But because there is, for this particular issue, a quick check that can be performed to avoid traceback, it is worth adding it
Julien Duroure self-assigned this 2021-09-07 13:29:54 +02:00
Member
Proposed PR: https://github.com/KhronosGroup/glTF-Blender-IO/pull/1464

This issue was referenced by 4d562682c0

This issue was referenced by 4d562682c099ce740d705893008a91a30a206710
Member

Changed status from 'Needs Developer To Reproduce' to: 'Resolved'

Changed status from 'Needs Developer To Reproduce' to: 'Resolved'
Sign in to join this conversation.
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#91217
No description provided.