The "material_index" attribute is expected to exist by many operations, but that is not always the case. Using a fallback value prevents crashing in case the attribute has been removed. A default material is already supported when the index is not in range of the actual material slots on an object or grease pencil data block respectively. Pull Request: https://projects.blender.org/blender/blender/pulls/138303