"ReferenceError: StructRNA of type Mesh has been removed" when accessing mesh data (created using depsgraph evaluation) after rendering by script #74092

Open
opened 2020-02-21 22:40:42 +01:00 by Julien Duroure · 12 comments
Member

System Information
Operating system: linux mint
Graphics card: Nvidia GTX 860M

Blender Version
Broken: 2.82
Worked: ?

From scripting, after rendering, some temporary mesh (created using depsgraph evaluation) are no more valid, and display error when you want to access it
Error is ReferenceError: StructRNA of type Mesh has been removed

How to reproduce:

  • Open the blend file
  • Execute the script from text editor

If at least one of the if Trues is changed to if False, the crash goes away.

crashy_cube.zip

script.py

import bpy
ob = bpy.data.objects['Cube']
edge_split = ob.modifiers.new('Temporary_Auto_Smooth', 'EDGE_SPLIT')
ob.data.use_auto_smooth = False

depsgraph = bpy.context.evaluated_depsgraph_get()
mesh_owner = ob.evaluated_get(depsgraph)
mesh = mesh_owner.to_mesh(preserve_all_data_layers=True, depsgraph=depsgraph)

if True:
    ob.data.use_auto_smooth = True 
    ob.modifiers.remove(edge_split)

if True:
    scn = bpy.data.scenes.new('temp scene')
    scn.use_nodes = True
    scn.node_tree.nodes.remove(scn.node_tree.nodes['Render Layers'])
    bpy.ops.render.render(scene=scn.name, write_still=True)

print(mesh.name)
**System Information** Operating system: linux mint Graphics card: Nvidia GTX 860M **Blender Version** Broken: 2.82 Worked: ? From scripting, after rendering, some temporary mesh (created using depsgraph evaluation) are no more valid, and display error when you want to access it Error is ReferenceError: StructRNA of type Mesh has been removed How to reproduce: * Open the blend file * Execute the script from text editor If at least one of the if Trues is changed to if False, the crash goes away. [crashy_cube.zip](https://archive.blender.org/developer/F8359974/crashy_cube.zip) [script.py](https://archive.blender.org/developer/F8359977/script.py) ``` import bpy ob = bpy.data.objects['Cube'] edge_split = ob.modifiers.new('Temporary_Auto_Smooth', 'EDGE_SPLIT') ob.data.use_auto_smooth = False depsgraph = bpy.context.evaluated_depsgraph_get() mesh_owner = ob.evaluated_get(depsgraph) mesh = mesh_owner.to_mesh(preserve_all_data_layers=True, depsgraph=depsgraph) if True: ob.data.use_auto_smooth = True ob.modifiers.remove(edge_split) if True: scn = bpy.data.scenes.new('temp scene') scn.use_nodes = True scn.node_tree.nodes.remove(scn.node_tree.nodes['Render Layers']) bpy.ops.render.render(scene=scn.name, write_still=True) print(mesh.name) ```
Author
Member

Added subscriber: @JulienDuroure

Added subscriber: @JulienDuroure
Member

Added subscriber: @elm19087

Added subscriber: @elm19087

Added subscriber: @iss

Added subscriber: @iss

I am not really familiar with depsgraph implementation here, but I will assume, that bpy.ops.render.render() will use depsgraph to evaluate another scene, so your mesh instance will be destroyed by calling this operator.

You could put

depsgraph = bpy.context.evaluated_depsgraph_get()
mesh_owner = ob.evaluated_get(depsgraph)
mesh = mesh_owner.to_mesh(preserve_all_data_layers=True, depsgraph=depsgraph)

in function and call it before and after rendering to get evaluated mesh.

I am not really familiar with depsgraph implementation here, but I will assume, that ` bpy.ops.render.render()` will use depsgraph to evaluate another scene, so your mesh instance will be destroyed by calling this operator. You could put ``` depsgraph = bpy.context.evaluated_depsgraph_get() mesh_owner = ob.evaluated_get(depsgraph) mesh = mesh_owner.to_mesh(preserve_all_data_layers=True, depsgraph=depsgraph) ``` in function and call it before and after rendering to get evaluated mesh.

Added subscriber: @mano-wii

Added subscriber: @mano-wii

Changed status from 'Needs Triage' to: 'Needs User Info'

Changed status from 'Needs Triage' to: 'Needs User Info'

@JulienDuroure, did @iss's comment help solve the problem?
(I don't know if it is worth investigating further as this does not seem like a bug, but it works as intended although poorly documented).

@JulienDuroure, did @iss's comment help solve the problem? (I don't know if it is worth investigating further as this does not seem like a bug, but it works as intended although poorly documented).
Author
Member

Well, if mesh instance is destroyed by calling ops.render.render(), we will have to refactorize the code to render first, and evaluate after (The complete code is of course not simplier than this example: this is for glTF export).
Is there any problem to evaluate it twice? (performance, memory usage?)

For a pure user point of view, maybe the following can help:

  • better documentation of the "issue"
  • If instance is destroyed, is there a way to change python mesh object to None? This will avoid to have this error
Well, if mesh instance is destroyed by calling ops.render.render(), we will have to refactorize the code to render first, and evaluate after (The complete code is of course not simplier than this example: this is for glTF export). Is there any problem to evaluate it twice? (performance, memory usage?) For a pure user point of view, maybe the following can help: * better documentation of the "issue" * If instance is destroyed, is there a way to change python mesh object to None? This will avoid to have this error
Author
Member

Changed status from 'Needs User Info' to: 'Needs Triage'

Changed status from 'Needs User Info' to: 'Needs Triage'

Technically bpy.ops.render.render() should use it's own depsgraph and it should be an instance, not a new state, so this may be a bug.
I was just suggesting quick workaround.

Technically `bpy.ops.render.render()` should use it's own depsgraph and it should be an instance, not a new state, so this may be a bug. I was just suggesting quick workaround.
Author
Member

Let's add the dependency graph tag, as it seems to be linked to it

Let's add the dependency graph tag, as it seems to be linked to it
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Philipp Oeser removed the
Interest
Python API
label 2023-02-10 09:04:42 +01:00
Philipp Oeser added the
Interest
Core
label 2023-02-10 11:09:54 +01: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
5 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#74092
No description provided.