Commit: 9fca9b99534923b69f5b2bb59f51d117aed81bac
Author: Sergey Sharybin
Date:   Tue Apr 7 11:36:59 2020 +0200
Branches: master
https://developer.blender.org/rB9fca9b99534923b69f5b2bb59f51d117aed81bac

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

===================================================================

M       source/blender/blenkernel/intern/mesh_convert.c

===================================================================

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;
 }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to