constant crashes when assigning evaluated mesh to obj after recent depsgraph changes #64735

Closed
opened 2019-05-16 23:58:42 +02:00 by MACHIN3 · 17 comments

System Information
Operating system: Linux-4.13.10-041310-generic-x86_64-with-debian-stretch-sid 64 Bits
Graphics card: GeForce GTX 1050/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 390.67

Blender Version
Broken: version: 2.80 (sub 68), branch: master, commit date: 2019-05-16 18:01, hash: d726d7e462

Short description of error
I'm trying to apply modifiers of an object, but am getting crashes constantly, when assigning the evaluated mesh to the object's data block.

Exact steps for others to reproduce the error

video demo

**System Information** Operating system: Linux-4.13.10-041310-generic-x86_64-with-debian-stretch-sid 64 Bits Graphics card: GeForce GTX 1050/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 390.67 **Blender Version** Broken: version: 2.80 (sub 68), branch: master, commit date: 2019-05-16 18:01, hash: `d726d7e462` **Short description of error** I'm trying to apply modifiers of an object, but am getting crashes constantly, when assigning the evaluated mesh to the object's data block. **Exact steps for others to reproduce the error** * load [applying_modifiers_after_the_recent_despgaph_changes.blend](https://archive.blender.org/developer/F7041899/applying_modifiers_after_the_recent_despgaph_changes.blend) * uncommend line 9 and run the script, which assignes the data block of the evaluated object, it should crash * reload and uncomment line 10 this time, which assinged the result of to_mesh(), it should also crash [video demo ](https://www.youtube.com/watch?v=ilxd11_TyuU)
Author

Added subscriber: @MACHIN3

Added subscriber: @MACHIN3

Added subscriber: @rlguy

Added subscriber: @rlguy

I am also experiencing this issue and am able to reproduce both crashes using the .blend file (Window 10 Home).

I am also experiencing this issue and am able to reproduce both crashes using the .blend file (Window 10 Home).
Author

Using active.data = bpy.data.meshes.new_from_object(active_eval)
as mentioend here , seems to work.

Using `active.data = bpy.data.meshes.new_from_object(active_eval)` [as mentioend here ](https://developer.blender.org/rB32d5d127cb49743578e8e1e9882d8a707a4e848e), seems to work.

Added subscribers: @Sergey, @brecht

Added subscribers: @Sergey, @brecht

@Sergey, we should have a warning similar to #64731 here I think, when assigning an ID to an ID with LIB_TAG_NO_MAIN not matching.

@Sergey, we should have a warning similar to #64731 here I think, when assigning an ID to an ID with `LIB_TAG_NO_MAIN` not matching.

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Sergey Sharybin self-assigned this 2019-05-17 10:28:09 +02:00

As the updated documentation of to_mesh() states: the object is the owner of the result of to_mesh(). It is short-living, and can not be referenced by other objects from your file (it can be referenced by a temporary object though).

The proper way of achieving your goal is to put mesh to the main database in the following way: bpy.data.meshes.new_from_object(active_eval). Note, that this will also ensure all other pointers in the mesh are valid form within main database (for example, mesh will not reference materials from dependency graph).

The entire script becomes this:

import bpy

active = bpy.context.active_object

dg = bpy.context.evaluated_depsgraph_get()

active_eval = active.evaluated_get(dg)

active.data = bpy.data.meshes.new_from_object(active_eval)

I've made this more explicit in the RNA documentation and Python examples in 5186cfbea4.

Would be cool to automatically detect unsupported pointers assignment, but that is a bit tricky. Mainly because a lot of scripts are relying on the possibility to temporarily modify objects in weird and wonderful ways. Maybe @brecht can think of some way improving error reporting for such cases without being too intrusive for the existing scripts?

This exact report i wouldn't consider a bug. Just script code requires a bit tweaking, and after that it is guaranteed to be non-crashing (before the dependency graph changes this script wouldn't immediately, but will create a wrong and corrupted .blend file, due to materials and animation pointing to the IDs from the dependency graph).

Thanks for the report, closing!

As the updated documentation of to_mesh() states: the object is the owner of the result of `to_mesh()`. It is short-living, and can not be referenced by other objects from your file (it can be referenced by a temporary object though). The proper way of achieving your goal is to put mesh to the main database in the following way: ` bpy.data.meshes.new_from_object(active_eval)`. Note, that this will also ensure all other pointers in the mesh are valid form within main database (for example, mesh will not reference materials from dependency graph). The entire script becomes this: ``` import bpy active = bpy.context.active_object dg = bpy.context.evaluated_depsgraph_get() active_eval = active.evaluated_get(dg) active.data = bpy.data.meshes.new_from_object(active_eval) ``` I've made this more explicit in the RNA documentation and Python examples in 5186cfbea4. Would be cool to automatically detect unsupported pointers assignment, but that is a bit tricky. Mainly because a lot of scripts are relying on the possibility to temporarily modify objects in weird and wonderful ways. Maybe @brecht can think of some way improving error reporting for such cases without being too intrusive for the existing scripts? This exact report i wouldn't consider a bug. Just script code requires a bit tweaking, and after that it is guaranteed to be non-crashing (before the dependency graph changes this script wouldn't immediately, but will create a wrong and corrupted .blend file, due to materials and animation pointing to the IDs from the dependency graph). Thanks for the report, closing!

In #64735#681254, @brecht wrote:
@Sergey, we should have a warning similar to #64731 here I think, when assigning an ID to an ID with LIB_TAG_NO_MAIN not matching.

Unfortunately, we can not do this easily. There are scripts which are creating temporary objects with mesh pointing to a result of evaluated to_mesh(). This is all fine if the object is removed afterwards.

If the assignment is based on LIB_TAG_NO_MAIN then we would need some way to create out-of-main objects as well.

> In #64735#681254, @brecht wrote: > @Sergey, we should have a warning similar to #64731 here I think, when assigning an ID to an ID with `LIB_TAG_NO_MAIN` not matching. Unfortunately, we can not do this easily. There are scripts which are creating temporary objects with mesh pointing to a result of evaluated `to_mesh()`. This is all fine if the object is removed afterwards. If the assignment is based on `LIB_TAG_NO_MAIN` then we would need some way to create out-of-main objects as well.

If scripts need to do that, I think they should be using bpy.data.meshes.new_from_object() instead?

If scripts need to do that, I think they should be using `bpy.data.meshes.new_from_object()` instead?

That isn't strictly speaking the same due to material, animation, shape keys pointers. Not sure how much problematic it is in the reality though.

That isn't strictly speaking the same due to material, animation, shape keys pointers. Not sure how much problematic it is in the reality though.

Note: started the patch which is aimed to help preventing unsupported configurations: D4884.

Note: started the patch which is aimed to help preventing unsupported configurations: [D4884](https://archive.blender.org/developer/D4884).
Author

@Sergey Thanks, you've been very helpful. How would you apply mods now, while keeping the materials assigned as they are by mods like bevel for instance. See apply_mods_keep_materials.blend

Is the only solution to first use to_mesh() to check the material indices for each face, and then reapply them accordingly on the mesh created from new_from_object()? Is this what the Apply button in the mod panel does?

@Sergey Thanks, you've been very helpful. How would you apply mods now, while keeping the materials assigned as they are by mods like bevel for instance. See [apply_mods_keep_materials.blend](https://archive.blender.org/developer/F7043683/apply_mods_keep_materials.blend) Is the only solution to first use to_mesh() to check the material indices for each face, and then reapply them accordingly on the mesh created from new_from_object()? Is this what the Apply button in the mod panel does?

@MACHIN3, thanks for the file, saved some time verifying the fix. Committed at 848967c21d.

P.S. Maybe next time open a new report. Much easier to keep a history of changes and references to reports.

@MACHIN3, thanks for the file, saved some time verifying the fix. Committed at 848967c21d. P.S. Maybe next time open a new report. Much easier to keep a history of changes and references to reports.
Author

Awesome, wasn't sure if it's a bug or intended behavior. And while at it. It also doesn't/didn't preserve use_auto_smooth and I assume auto_smooth_angle

Awesome, wasn't sure if it's a bug or intended behavior. And while at it. It also doesn't/didn't preserve `use_auto_smooth` and I assume `auto_smooth_angle`

Autosmooth should also be preserved now. Is it still broken for you?

Autosmooth should also be preserved now. Is it still broken for you?
Author

I'm still on the old build. I assume not, if this is the fix: mesh_in_bmain->smoothresh = mesh->smoothresh;

I'm still on the old build. I assume not, if this is the fix: `mesh_in_bmain->smoothresh = mesh->smoothresh;`
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#64735
No description provided.