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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user