Python API allows setting negative material indices #105577
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#105577
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
System Information
Operating system: Windows-10-10.0.19045-SP0 64 Bits
Graphics card: NVIDIA GeForce GTX 1070 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 516.94
Blender Version
Broken: version: 3.4.1, branch: blender-v3.4-release, commit date: 2022-12-19 17:00, hash:
rB55485cb379f7
and version: 3.6.0 Alpha, branch: main, commit date: 2023-03-06 22:38, hash:175b1b449ec2
Worked: 3.3.4
Caused by
f1c0249f34
Short description of error
The Python API now allows for negative material indices to be set, frequently crashing Blender if the affected mesh has more than one material slot (there appear to be optimizations in place that assume every polygon is using the first material slot when there's only one material slot). If Blender doesn't crash, the polygons with negative material indices become invisible with Solid Viewport Shading.
The material indices can be set negative with both
MeshPolygon.material_index
and the newermaterial_index
attribute.This seems to have come about from the change in 3.4.0 that moved material indices to a generic attribute.
There was a similar issue with Geometry Nodes that got fixed: #100952
Exact steps for others to reproduce the error
Select a default cube and run the following script:
Alternative steps that are likely to crash Blender:
If Blender doesn't crash immediately from running the script, I find that going in and out of Edit mode a few times causes a crash pretty quickly.
A .blend containing a default cube with two material slots and all material indices already set to -1 is also attached.
If the
material_index
attribute exists, the material indices can also be set negative using it:Interestingly, I noticed that the
hard_min
of thematerial_index
property ofMeshPolygon
is still zero in 3.4, despite allowing negative values to be set:assert bpy.types.MeshPolygon.bl_rna.properties["material_index"].hard_min == 0
I'm not sure if there's an equivalent
hard_min
for thematerial_index
attribute, since it's a genericMeshPolygonIntProperty
.In fact, given the way the viewport handles negative material indices (crashing), negative material indices should not be allowed to be set in Python. Or the viewport shouldn't crash.
Well, since this is a regression, will raise priority.
Python API allows setting negative material indicesto Regression: Python API allows setting negative material indicesI made it not crash for 3.5, which I think lets us lower the priority and figure out a fix in 3.6 or later.
Personally I'm fine with just clamping, but from discussion in blender.chat others wanted to prevent it altogether which is even better.
Regression: Python API allows setting negative material indicesto Python API allows setting negative material indicesThis isn't a regression because it's a new API. Only new Python code that actually sets negative indices will be affected.
This is also an issue for many curve attributes, since we use
int8
attributes to store enum values. There is no validation there and I don't think there should be-- we should pay the performance and complexity cost only in once place (the Python API that sets potentially bad values) rather than everywhere in Blender.I'd like to solve this by bundling a validation function that changes an attribute value before it's set in the Python API. That can be included in the use of the existing
bke::AttributeValidator
class.Ah shoot, it looks like the material index setter in RNA is affected, I misread the report, sorry. That part should definitely be fixed. Then the lack of validation in the
mesh.attribuets
API is a totally separate topic in my opinion.