Page MenuHome

Blender freezes on evaluated_depsgraph_get when Python API is used to add/remove modifiers on an object
Closed, ResolvedPublic


System Information
Operating system: Windows 10 Home
Graphics card: GTX 1070 8GB

Blender Version
Broken: 2.80, .3076544c8c52, 2019-05-16

Short description of error

This issue was encountered while updating the FLIP Fluids addon for the recent rBe693918d40741b0839cea84d2e0c386cc262e0c3 API changes. I have reduced the issue to a simple script that causes Blender to freeze when calling the evaluated_depsgraph_get method.

It seems that adding a modifier to an object and then removing the modifier via the Python API is related to the freezing issue. The first time evaluated_depsgraph_get is called, the method completes successfully. On the second time it is called on another object, the freeze will occur.

Here is a short script that reproduces the issue:

import bpy

def test_mesh_evaluated(obj):
    modifier ="test_mod", "TRIANGULATE")
    print("Retrieving evaluated depsgraph...")
    depsgraph = bpy.context.evaluated_depsgraph_get()
    print("Retrieved evaluated depsgraph:", depsgraph)
    obj_eval = obj.evaluated_get(depsgraph)
    new_mesh = obj_eval.to_mesh()
cube_obj ="Cube")

cube_obj ="Cube.001")

The console output after running this script is:

Retrieving evaluated depsgraph...
Retrieved evaluated depsgraph: <bpy_struct, Depsgraph at 0x000002CF230DDD38>
Retrieving evaluated depsgraph...

Exact steps for others to reproduce the error

I have attached a .blend file that includes the script to reproduce this issue.

To reproduce:

  1. Open the .blend file
  2. Press 'Run Script', Blender freezes

To reproduce from a new .blend file:

  1. Duplicate the default cube so that there are two cubes in the scene (Cube, Cube.001)
  2. Run the script, Blender freezes

Event Timeline

Sergey Sharybin (sergey) claimed this task.
Sergey Sharybin (sergey) triaged this task as Confirmed, Medium priority.

The issue here is that you're trying to remove mesh from, but that mesh is owned by the object. It is to be cleared using object.to_mesh_clear(). That should solve Blender locking.

I think we should have something like this

1diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c
2index f6fee2580b8..abcaccd7b6b 100644
3--- a/source/blender/makesrna/intern/rna_main_api.c
4+++ b/source/blender/makesrna/intern/rna_main_api.c
5@@ -125,6 +125,14 @@ static void rna_Main_ID_remove(Main *bmain,
6 bool do_ui_user)
7 {
8 ID *id = id_ptr->data;
9+ if (id->tag & LIB_TAG_NO_MAIN) {
10+ BKE_reportf(reports,
12+ "%s '%s' is outside of main database and can not be removed from it",
13+ BKE_idcode_to_name(GS(id->name)),
14+ id->name + 2);
15+ return;
16+ }
17 if (do_unlink) {
18 BKE_id_delete(bmain, id);
to prevent such mistakes. @Brecht Van Lommel (brecht), any suggestions/objections?