Skip to content

IndexError: vertex_groups index out of range when exporting objects with stale vertex group data #561

@kyleyoungblom

Description

@kyleyoungblom

Description

When exporting from Blender to ZBrush, the export fails with an IndexError if an object's mesh-level vertex group data (me.vertices[vert].groups) references a group index that is out of range of obj.vertex_groups.

Error

File "GoB.py / gob_export.py", line ~1092, in exportGoZ
    if vg.weight >= prefs().export_weight_threshold and obj.vertex_groups[vg.group].name.lower() != 'mask':
IndexError: bpy_prop_collection[index]: index 0 out of range, size 0

Affected versions

Confirmed in GoB-4_0_2 and GoB-4_2_3 (latest). In v4_2_3 this is in gob_export.py line 401.

Fix

Add a bounds check before the index access:

# Before
if vg.weight >= prefs().export_weight_threshold and obj.vertex_groups[vg.group].name.lower() != 'mask':

# After
if vg.weight >= prefs().export_weight_threshold and vg.group < len(obj.vertex_groups) and obj.vertex_groups[vg.group].name.lower() != 'mask':

This short-circuits safely when vg.group is out of range of the object's vertex groups collection.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions