Debug assert in uv layer data.foreach_get when called on an Edit Mode mesh #107416

Closed
opened 2023-04-28 01:16:42 +02:00 by Thomas Barlow · 5 comments
Member

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 531.41

Blender Version
Broken: version: 3.5.1 and 3.6.0 Alpha, branch: main, commit date: 2023-04-25 23:13, hash: 91020ccde15a
Worked: 3.4.1

Short description of error
Since 3.5, while in Edit Mode, attempting to get all uvs of a MeshUVLoopLayer through uv_layer.data.foreach_get("uv", my_list) will fill my_list with None or fail an assertion in debug builds: https://projects.blender.org/blender/blender/src/tag/v3.5.1/source/blender/python/intern/bpy_rna.c#L5451

In 3.4, unless my_list had zero length, this would fail and raise an Error because the length of the UV layer data is zero while in Edit Mode which is not the same as my_list: https://projects.blender.org/blender/blender/src/tag/v3.4.1/source/blender/makesrna/intern/rna_access.c#L4403

(the newer API of uv_layer.uv.foreach_get("vector", my_list) or using the foreach_get function of the UV layer's attribute fail as expected while in Edit Mode when my_list has non-zero length, so no problems with those.)

Exact steps for others to reproduce the error
Open a mesh with at least one uv_layer in Edit Mode and run the below script. On a debug build, you may need to ctrl+c to stop the script so that the stacktrace from the assertion can be printed.

import bpy

# Enter edit mode with a mesh and then:
me = bpy.context.object.data

# If the mesh weren't in Edit Mode, this would be the correct length of the list
uvs = [0.0] * (len(me.loops) * 2)

uvs_too_long = uvs + [0.0] * 1000

uv_layer = me.uv_layers[0]

# Currently in Edit Mode, so the length gets reported as zero.
assert len(uv_layer.data) == 0

# For a default cube, fails as expected with "Array length mismatch (expected 0, got 48)"
# me.uv_layers[0].uv.foreach_get("vector", uvs)
# For a default cube, fails as expected with "Array length mismatch (expected 0, got 48)"
# me.attributes[uv_layer.name].data.foreach_get("vector", uvs)

# On debug builds, an assertion will fail
uv_layer.data.foreach_get("uv", uvs)

# On release builds, the list will be filled with None
assert all(uv is None for uv in uvs)

# It doesn't seem to matter what size list is used, the entire list is filled with None
uv_layer.data.foreach_get("uv", uvs_too_long)
assert all(uv is None for uv in uvs_too_long)
**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 531.41 **Blender Version** Broken: version: 3.5.1 and 3.6.0 Alpha, branch: main, commit date: 2023-04-25 23:13, hash: `91020ccde15a` Worked: 3.4.1 **Short description of error** Since 3.5, while in Edit Mode, attempting to get all uvs of a `MeshUVLoopLayer` through `uv_layer.data.foreach_get("uv", my_list)` will fill `my_list` with `None` or fail an assertion in debug builds: https://projects.blender.org/blender/blender/src/tag/v3.5.1/source/blender/python/intern/bpy_rna.c#L5451 In 3.4, unless `my_list` had zero length, this would fail and raise an Error because the length of the UV layer data is zero while in Edit Mode which is not the same as `my_list`: https://projects.blender.org/blender/blender/src/tag/v3.4.1/source/blender/makesrna/intern/rna_access.c#L4403 (the newer API of `uv_layer.uv.foreach_get("vector", my_list)` or using the `foreach_get` function of the UV layer's attribute fail as expected while in Edit Mode when `my_list` has non-zero length, so no problems with those.) **Exact steps for others to reproduce the error** Open a mesh with at least one uv_layer in Edit Mode and run the below script. On a debug build, you may need to ctrl+c to stop the script so that the stacktrace from the assertion can be printed. ```py import bpy # Enter edit mode with a mesh and then: me = bpy.context.object.data # If the mesh weren't in Edit Mode, this would be the correct length of the list uvs = [0.0] * (len(me.loops) * 2) uvs_too_long = uvs + [0.0] * 1000 uv_layer = me.uv_layers[0] # Currently in Edit Mode, so the length gets reported as zero. assert len(uv_layer.data) == 0 # For a default cube, fails as expected with "Array length mismatch (expected 0, got 48)" # me.uv_layers[0].uv.foreach_get("vector", uvs) # For a default cube, fails as expected with "Array length mismatch (expected 0, got 48)" # me.attributes[uv_layer.name].data.foreach_get("vector", uvs) # On debug builds, an assertion will fail uv_layer.data.foreach_get("uv", uvs) # On release builds, the list will be filled with None assert all(uv is None for uv in uvs) # It doesn't seem to matter what size list is used, the entire list is filled with None uv_layer.data.foreach_get("uv", uvs_too_long) assert all(uv is None for uv in uvs_too_long) ```
Thomas Barlow added the
Priority
Normal
Type
Report
Status
Needs Triage
labels 2023-04-28 01:16:42 +02:00
Member

Thanks for the report. I can confirm.

Thanks for the report. I can confirm.
Member

@Baardaap : interested?

@Baardaap : interested?

Very, a bit swamped in work though.

Might be related to #107500 , which I'm currently trying to patch up...

I'll self assign and try to look at it in the near future.

Very, a bit swamped in work though. Might be related to https://projects.blender.org/blender/blender/issues/107500 , which I'm currently trying to patch up... I'll self assign and try to look at it in the near future.
Martijn Versteegh self-assigned this 2023-05-24 10:43:51 +02:00

Initial investigation results:

  • foreach_attr_type tries to get the type of the MeshUVLoopLayer.data.uv property
  • because the object is in edit mode, the length of the .data collection is 0
  • because it can't iterate the properties of data[0] it can't find the type of data[0].uv
    -> it fails on an assert of 'invalid type'.

It's not a straightforward result of the change to attribute layers I think.. but probably related.

Will try to think of a fix.

Initial investigation results: - foreach_attr_type tries to get the type of the MeshUVLoopLayer.data.uv property - because the object is in edit mode, the length of the .data collection is 0 - because it can't iterate the properties of data[0] it can't find the type of data[0].uv -> it fails on an assert of 'invalid type'. It's not a straightforward result of the change to attribute layers I *think*.. but probably related. Will try to think of a fix.

@Chris_Blackbourn this is not the same issue as #107500 , but if you have ideas on how to solve I don't object (at all!) ;-)

@Chris_Blackbourn this is not the same issue as #107500 , but if you have ideas on how to solve I don't object (at all!) ;-)
Blender Bot added
Status
Resolved
and removed
Status
Confirmed
labels 2023-07-05 20:06:27 +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
4 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#107416
No description provided.