From dfb963c70df515213c452094c20c83720bc017ee Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 18 May 2021 12:53:28 +1000 Subject: Fix T88026: Repeated switch to rendered viewport crashes Resolve ownership ambiguity with shared physics pointers. Previously, LIB_ID_CREATE_NO_MAIN allowed pointer sharing with the source ID so physics caches can be shared between original and evaluated data: (Object.soft.shared & Object.rigidbody_object.shared). This only worked properly for LIB_TAG_COPIED_ON_WRITE ID's, as LIB_TAG_NO_MAIN can be used in situations where the original ID's lifetime limited by it's original data. This commit adds `LIB_ID_COPY_SET_COPIED_ON_WRITE` so ID's only share memory with original data for ID's evaluated in the depsgraph. For all other uses, a full copy of physics data is made. Ref D11228#287094 --- source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source/blender/depsgraph') diff --git a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc index e1959c8bf5e..43bcb23a38a 100644 --- a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc +++ b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc @@ -304,7 +304,8 @@ bool id_copy_inplace_no_main(const ID *id, ID *newid) bool result = (BKE_id_copy_ex(nullptr, (ID *)id_for_copy, &newid, - LIB_ID_COPY_LOCALIZE | LIB_ID_CREATE_NO_ALLOCATE) != nullptr); + (LIB_ID_COPY_LOCALIZE | LIB_ID_CREATE_NO_ALLOCATE | + LIB_ID_COPY_SET_COPIED_ON_WRITE)) != nullptr); #ifdef NESTED_ID_NASTY_WORKAROUND if (result) { @@ -333,7 +334,8 @@ bool scene_copy_inplace_no_main(const Scene *scene, Scene *new_scene) bool result = (BKE_id_copy_ex(nullptr, id_for_copy, (ID **)&new_scene, - LIB_ID_COPY_LOCALIZE | LIB_ID_CREATE_NO_ALLOCATE) != nullptr); + (LIB_ID_COPY_LOCALIZE | LIB_ID_CREATE_NO_ALLOCATE | + LIB_ID_COPY_SET_COPIED_ON_WRITE)) != nullptr); #ifdef NESTED_ID_NASTY_WORKAROUND if (result) { -- cgit v1.2.3