Attempting to modify UVs with bpy results in crash with EXCEPTION_ACCESS_VIOLATION #112342

Closed
opened 2023-09-13 18:24:50 +02:00 by Jonko · 2 comments

System Information
Operating system: Windows 11
Graphics card: Intel Iris Xe Graphics

Blender Version
Broken: 3.5.1, 3.6.2, 4.0.0-alpha+main.fca8df9415b1-windows.amd64-release
Worked: 3.4.1

Short description of error
I wrote a basic plugin for Blender 3.4 to import a custom model format from a game I'm working on (specifically, I export the model data to a JSON file and then import that JSON using bpy). The script worked perfectly in 3.4, but when running in 3.6 (and tested on the latest 4.0 alpha as well), the script causes blender to crash. The specific error is:

Error   : EXCEPTION_ACCESS_VIOLATION
Address : 0x00007FF9BBBB832A
Module  : tbbmalloc.dll
Thread  : 00001afc
Writing: C:\Users\jonko\AppData\Local\Temp\blender.crash.txt
Error loading symbols C:\Program Files\Blender Foundation\Blender 3.6\blender.pdb
        error:0xc0000005
        size = 110227456
        base=0x00007FF613890000

blender.crash.txt is empty.

You can see my original script here. By commenting out stuff and trying to run it, I have narrowed down the cause to line 79:

uvlayer.data[loop_idx].uv = uvcoords[vert_idx]

I read that the MeshUVLoopLayer class was modified in Blender 3.5, so I tried upgrading this line to what looks like the new format:

uvlayer.uv[loop_idx].vector = uvcoords[vert_idx]

However, the same crash persists.

I have verified that both uvlayer.uv[loop_idx.vector and uvcoords[vert_idx] can be printed to the console without issue. I will also attach a sample model JSON file.

Exact steps for others to reproduce the error

  1. Download the python script and model JSON file linked above
  2. Comment out lines 14-21 and 81-84 of the script (these lines import the textures for mats -- they don't affect the crash in my testing and this simplifies things)
  3. From the command line, run blender --background -noaudio -P ./sge_import.py ./OB0065O.sge.json blend (substituting the correct paths to those files)
  4. Observe crash

Note: I'm running the script headless because it's faster, but the same crash occurs when you attempt to use it as an Import/Export add-on.

**System Information** Operating system: Windows 11 Graphics card: Intel Iris Xe Graphics **Blender Version** Broken: 3.5.1, 3.6.2, 4.0.0-alpha+main.fca8df9415b1-windows.amd64-release Worked: 3.4.1 **Short description of error** I wrote a basic plugin for Blender 3.4 to import a custom model format from a game I'm working on (specifically, I export the model data to a JSON file and then import that JSON using bpy). The script worked perfectly in 3.4, but when running in 3.6 (and tested on the latest 4.0 alpha as well), the script causes blender to crash. The specific error is: ``` Error : EXCEPTION_ACCESS_VIOLATION Address : 0x00007FF9BBBB832A Module : tbbmalloc.dll Thread : 00001afc Writing: C:\Users\jonko\AppData\Local\Temp\blender.crash.txt Error loading symbols C:\Program Files\Blender Foundation\Blender 3.6\blender.pdb error:0xc0000005 size = 110227456 base=0x00007FF613890000 ``` blender.crash.txt is empty. You can see my original script [here](https://github.com/haroohie-club/HeiretsuTranslationUtility/blob/main/HaruhiHeiretsuLib/Blender/sge_import.py). By commenting out stuff and trying to run it, I have narrowed down the cause to line 79: ```py uvlayer.data[loop_idx].uv = uvcoords[vert_idx] ``` I read that the MeshUVLoopLayer class was [modified in Blender 3.5](https://docs.blender.org/api/3.5/change_log.html#bpy-types-meshuvlooplayer), so I tried upgrading this line to what looks like the new format: ```py uvlayer.uv[loop_idx].vector = uvcoords[vert_idx] ``` However, the same crash persists. I have verified that both `uvlayer.uv[loop_idx.vector` and `uvcoords[vert_idx]` can be printed to the console without issue. I will also attach a sample model JSON file. **Exact steps for others to reproduce the error** 1. Download the python script and model JSON file linked above 2. Comment out lines 14-21 and 81-84 of the script (these lines import the textures for mats -- they don't affect the crash in my testing and this simplifies things) 3. From the command line, run `blender --background -noaudio -P ./sge_import.py ./OB0065O.sge.json blend` (substituting the correct paths to those files) 4. Observe crash Note: I'm running the script headless because it's faster, but the same crash occurs when you attempt to use it as an Import/Export add-on.
Jonko added the
Priority
Normal
Type
Report
Status
Needs Triage
labels 2023-09-13 18:24:51 +02:00
Member

I think this might be duplicate of #107500 because the linked script creates the new uvlayer and the new color_layer and then tries to use the uvlayer variable that may no longer be valid because another layer (color_layer) was added afterwards.

    uvlayer = mesh.uv_layers.new()
    color_layer = mesh.vertex_colors.new()
    for face in mesh.polygons:
        for vert_idx, loop_idx in zip(face.vertices, face.loop_indices):
            color_layer.data[vert_idx].color = (colors[vert_idx]['R'], colors[vert_idx]['G'], colors[vert_idx]['B'], colors[vert_idx]['A'])
            uvlayer.data[loop_idx].uv = uvcoords[vert_idx]

For a potential workaround, I would suggest:

    uvlayer = mesh.uv_layers.new()
    uvlayer_name = uvlayer.name
    color_layer = mesh.vertex_colors.new()
    # Creating the color layer has invalidated the reference to the uv layer, so get it again.
    uvlayer = mesh.uv_layers[uvlayer_name]
    for face in mesh.polygons:
        for vert_idx, loop_idx in zip(face.vertices, face.loop_indices):
            color_layer.data[vert_idx].color = (colors[vert_idx]['R'], colors[vert_idx]['G'], colors[vert_idx]['B'], colors[vert_idx]['A'])
            uvlayer.data[loop_idx].uv = uvcoords[vert_idx]

Re-ordering the creation of the layers so that color_layer is created first would probably also work, but I wouldn't recommend it since its relying on the internal ordering of the layers.

I think this might be duplicate of https://projects.blender.org/blender/blender/issues/107500 because the linked script creates the new `uvlayer` and the new `color_layer` and then tries to use the `uvlayer` variable that may no longer be valid because another layer (`color_layer`) was added afterwards. ```py uvlayer = mesh.uv_layers.new() color_layer = mesh.vertex_colors.new() for face in mesh.polygons: for vert_idx, loop_idx in zip(face.vertices, face.loop_indices): color_layer.data[vert_idx].color = (colors[vert_idx]['R'], colors[vert_idx]['G'], colors[vert_idx]['B'], colors[vert_idx]['A']) uvlayer.data[loop_idx].uv = uvcoords[vert_idx] ``` For a potential workaround, I would suggest: ```py uvlayer = mesh.uv_layers.new() uvlayer_name = uvlayer.name color_layer = mesh.vertex_colors.new() # Creating the color layer has invalidated the reference to the uv layer, so get it again. uvlayer = mesh.uv_layers[uvlayer_name] for face in mesh.polygons: for vert_idx, loop_idx in zip(face.vertices, face.loop_indices): color_layer.data[vert_idx].color = (colors[vert_idx]['R'], colors[vert_idx]['G'], colors[vert_idx]['B'], colors[vert_idx]['A']) uvlayer.data[loop_idx].uv = uvcoords[vert_idx] ``` Re-ordering the creation of the layers so that `color_layer` is created first would probably also work, but I wouldn't recommend it since its relying on the internal ordering of the layers.
Author

It looks like it is a dupe of that bug because your solution fixed it! I'm going to close in favor of it. As long as this behavior is documented, I don't think it's a huge issue. Ideally, if you could add it to the 3.5 changenotes as well, that would have helped in discoverability.

It looks like it is a dupe of that bug because your solution fixed it! I'm going to close in favor of it. As long as this behavior is documented, I don't think it's a huge issue. Ideally, if you could add it to the 3.5 changenotes as well, that would have helped in discoverability.
Jonko closed this issue 2023-09-13 19:38:10 +02:00
Blender Bot added
Status
Archived
and removed
Status
Needs Triage
labels 2023-09-13 19:38:12 +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
2 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#112342
No description provided.