diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2020-04-07 12:36:59 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2020-04-07 13:50:45 +0300 |
commit | 9fca9b99534923b69f5b2bb59f51d117aed81bac (patch) | |
tree | 3a8d76c28097011f072281b12ad3355fb1d0cfae /source/blender/blenkernel/intern/mesh_convert.c | |
parent | 49deda4ca223fbfb33912ea7d14f9c2b77155f68 (diff) |
Fix crash using object.to_mesh() when in edit mode
The root of the issue was caused by mesh which was a result of to_mesh()
had the same edit_mesh pointer as the input object, causing double-free
error.
This fix makes it so result mesh does not have edit mesh pointer.
Motivation part behind this is to make the result of to_mesh() to be
somewhat independent from the input.
Differential Revision: https://developer.blender.org/D7361
Diffstat (limited to 'source/blender/blenkernel/intern/mesh_convert.c')
-rw-r--r-- | source/blender/blenkernel/intern/mesh_convert.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/mesh_convert.c b/source/blender/blenkernel/intern/mesh_convert.c index 74b79490d67..e24718ebe30 100644 --- a/source/blender/blenkernel/intern/mesh_convert.c +++ b/source/blender/blenkernel/intern/mesh_convert.c @@ -1155,9 +1155,21 @@ Mesh *BKE_mesh_new_from_object(Depsgraph *depsgraph, Object *object, bool preser /* Happens in special cases like request of mesh for non-mother meta ball. */ return NULL; } + /* The result must have 0 users, since it's just a mesh which is free-dangling data-block. * All the conversion functions are supposed to ensure mesh is not counted. */ BLI_assert(new_mesh->id.us == 0); + + /* It is possible that mesh came from modifier stack evaluation, which preserves edit_mesh + * pointer (which allows draw manager to access edit mesh when drawing). Normally this does + * not cause ownership problems because evaluated object runtime is keeping track of the real + * ownership. + * + * Here we are constructing a mesh which is supposed to be iondependent, which means no shared + * ownership is allowed, so we make sure edit mesh is reset to NULL (which is similar to as if + * one duplicates the objects and applies all the modifiers). */ + new_mesh->edit_mesh = NULL; + return new_mesh; } |