Mesh has invalid loop_triangles after validation #120152

Closed
opened 2024-04-02 02:20:40 +02:00 by Scurest · 3 comments
Contributor

System Information
Operating system: Linux
Graphics card:

Blender Version
Broken: 4.0, 4.1, 4.2
Worked: 3.6

Broke with 96ad44a462

Short description of error
When mesh.validate() corrects an invalid mesh, any cached loop_triangles/corner_tris are not discarded. Therefore if the cache existed before the validate call, the cache will retain the old invalid data even on the now-valid mesh.

This causes various problem like import-export errors and glitches in the 3D view.

Exact steps for others to reproduce the error
Run this script (from the command line with blender -b -P script.py is fine)

import bpy

# (1) Create an invalid mesh

mesh = bpy.data.meshes.new('Tri')
mesh.from_pydata([(0,0,0), (0,1,0), (1,0,0)], [], [(0,1,2), (1,2,0)])
ob = bpy.data.objects.new(mesh.name, mesh)
bpy.context.scene.collection.objects.link(ob)

# (2) Force calculation of mesh.loop_triangles

print('Num loops', len(mesh.loops))
for tri in mesh.loop_triangles:
    print(tri.loops[:])

# (3) Validate mesh

print('Validating...')
mesh.validate()

# (4) Access mesh.loop_triangles again

print('Num loops', len(mesh.loops))
for tri in mesh.loop_triangles:
    print(tri.loops[:])

The output is

Num loops 6
(0, 1, 2)
(3, 4, 5)
Validating...
Num loops 3
(0, 1, 2)
(3, 4, 5)

Note the invalid tri with out-of-bounds loop indices on the last line. In 3.6, that bad tri does not exist.

The problem does not appear if you comment out (2), because then the corner_tris_cache is not computed until after validation.

**System Information** Operating system: Linux Graphics card: **Blender Version** Broken: 4.0, 4.1, 4.2 Worked: 3.6 Broke with 96ad44a4628689b290e8c3f578c1148efe5f98b6 **Short description of error** When `mesh.validate()` corrects an invalid mesh, any cached loop_triangles/corner_tris are not discarded. Therefore if the cache existed before the validate call, the cache will retain the old invalid data even on the now-valid mesh. This causes various problem like [import-export errors](https://github.com/KhronosGroup/glTF-Blender-IO/issues/2171) and [glitches in the 3D view](https://projects.blender.org/blender/blender/issues/119823#issuecomment-1157208). **Exact steps for others to reproduce the error** Run this script (from the command line with `blender -b -P script.py` is fine) ```py import bpy # (1) Create an invalid mesh mesh = bpy.data.meshes.new('Tri') mesh.from_pydata([(0,0,0), (0,1,0), (1,0,0)], [], [(0,1,2), (1,2,0)]) ob = bpy.data.objects.new(mesh.name, mesh) bpy.context.scene.collection.objects.link(ob) # (2) Force calculation of mesh.loop_triangles print('Num loops', len(mesh.loops)) for tri in mesh.loop_triangles: print(tri.loops[:]) # (3) Validate mesh print('Validating...') mesh.validate() # (4) Access mesh.loop_triangles again print('Num loops', len(mesh.loops)) for tri in mesh.loop_triangles: print(tri.loops[:]) ``` The output is ``` Num loops 6 (0, 1, 2) (3, 4, 5) Validating... Num loops 3 (0, 1, 2) (3, 4, 5) ``` Note the invalid tri with out-of-bounds loop indices on the last line. In 3.6, that bad tri does not exist. The problem does not appear if you comment out (2), because then the corner_tris_cache is not computed until after validation.
Scurest added the
Priority
Normal
Type
Report
Status
Needs Triage
labels 2024-04-02 02:20:41 +02:00
Member

Can confirm. Looks like mesh.validate() should clear those cached data too.

Can confirm. Looks like `mesh.validate()` should clear those cached data too.
YimingWu added
Status
Confirmed
Module
Core
and removed
Status
Needs Triage
labels 2024-04-02 07:53:44 +02:00
Member

Just noting that this broke between good 7be0d1481c and bad 998e7f644f

Just noting that this broke between good 7be0d1481c67 and bad 998e7f644f6f
Member

Broke with 96ad44a462

CC @HooglyBoogly

Broke with 96ad44a4628689b290e8c3f578c1148efe5f98b6 CC @HooglyBoogly
Philipp Oeser added
Module
Modeling
Priority
High
and removed
Module
Core
Priority
Normal
labels 2024-04-02 10:13:42 +02:00
Blender Bot added
Status
Resolved
and removed
Status
Confirmed
labels 2024-04-04 17:21:36 +02:00
Sign in to join this conversation.
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
3 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#120152
No description provided.