Fix T100255: Make RigidBodyWorld (and effector_weights) collections refcounted.

Those collections were so far mainly just tagged as fake user (even
though a few places in code already incremented usercount on them).

Since we now clear the fakeuser flag when linking/appending data, ensure
that these collections are preserved by making these usages regular ID
refcounting ones.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D15783
This commit is contained in:
Bastien Montagne 2022-08-25 17:21:39 +02:00 committed by Bastien Montagne
parent b27856f12e
commit 500d815478
Notes: blender-bot 2023-02-14 07:39:44 +01:00
Referenced by issue #100255, After appending a scene containing rigid body objects, the RigidBodyWorld and RigidBodyConstraints directories are not saved.
9 changed files with 17 additions and 14 deletions

View File

@ -449,7 +449,7 @@ static void object_foreach_id(ID *id, LibraryForeachIDData *data)
if (object->soft->effector_weights) {
BKE_LIB_FOREACHID_PROCESS_IDSUPER(
data, object->soft->effector_weights->group, IDWALK_CB_NOP);
data, object->soft->effector_weights->group, IDWALK_CB_USER);
}
}
}

View File

@ -171,7 +171,7 @@ static void particle_settings_foreach_id(ID *id, LibraryForeachIDData *data)
}
if (psett->effector_weights) {
BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, psett->effector_weights->group, IDWALK_CB_NOP);
BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, psett->effector_weights->group, IDWALK_CB_USER);
}
if (psett->pd) {

View File

@ -1176,6 +1176,9 @@ RigidBodyWorld *BKE_rigidbody_world_copy(RigidBodyWorld *rbw, const int flag)
if (rbw->effector_weights) {
rbw_copy->effector_weights = MEM_dupallocN(rbw->effector_weights);
if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
id_us_plus((ID *)rbw->effector_weights->group);
}
}
if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
id_us_plus((ID *)rbw_copy->group);
@ -1205,9 +1208,9 @@ void BKE_rigidbody_world_groups_relink(RigidBodyWorld *rbw)
void BKE_rigidbody_world_id_loop(RigidBodyWorld *rbw, RigidbodyWorldIDFunc func, void *userdata)
{
func(rbw, (ID **)&rbw->group, userdata, IDWALK_CB_NOP);
func(rbw, (ID **)&rbw->constraints, userdata, IDWALK_CB_NOP);
func(rbw, (ID **)&rbw->effector_weights->group, userdata, IDWALK_CB_NOP);
func(rbw, (ID **)&rbw->group, userdata, IDWALK_CB_USER);
func(rbw, (ID **)&rbw->constraints, userdata, IDWALK_CB_USER);
func(rbw, (ID **)&rbw->effector_weights->group, userdata, IDWALK_CB_USER);
if (rbw->objects) {
int i;
@ -1424,7 +1427,7 @@ static bool rigidbody_add_object_to_scene(Main *bmain, Scene *scene, Object *ob)
if (rbw->group == NULL) {
rbw->group = BKE_collection_add(bmain, NULL, "RigidBodyWorld");
id_fake_user_set(&rbw->group->id);
id_us_plus(&rbw->group->id);
}
/* Add object to rigid body group. */
@ -1453,7 +1456,7 @@ static bool rigidbody_add_constraint_to_scene(Main *bmain, Scene *scene, Object
if (rbw->constraints == NULL) {
rbw->constraints = BKE_collection_add(bmain, NULL, "RigidBodyConstraints");
id_fake_user_set(&rbw->constraints->id);
id_us_plus(&rbw->constraints->id);
}
/* Add object to rigid body group. */

View File

@ -88,7 +88,7 @@ bool ED_rigidbody_constraint_add(
/* create constraint group if it doesn't already exits */
if (rbw->constraints == NULL) {
rbw->constraints = BKE_collection_add(bmain, NULL, "RigidBodyConstraints");
id_fake_user_set(&rbw->constraints->id);
id_us_plus(&rbw->constraints->id);
}
/* make rigidbody constraint settings */
ob->rigidbody_constraint = BKE_rigidbody_create_constraint(scene, ob, type);

View File

@ -1276,7 +1276,7 @@ static void rna_def_effector_weight(BlenderRNA *brna)
prop = RNA_def_property(srna, "collection", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "Collection");
RNA_def_property_pointer_sdna(prop, NULL, "group");
RNA_def_property_flag(prop, PROP_EDITABLE);
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT);
RNA_def_property_ui_text(prop, "Effector Collection", "Limit effectors to this collection");
RNA_def_property_update(prop, 0, "rna_EffectorWeight_dependency_update");

View File

@ -865,7 +865,7 @@ static void rna_def_rigidbody_world(BlenderRNA *brna)
prop = RNA_def_property(srna, "collection", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "Collection");
RNA_def_property_pointer_sdna(prop, NULL, "group");
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK);
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK | PROP_ID_REFCOUNT);
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(
prop, "Collection", "Collection containing objects participating in this simulation");
@ -873,7 +873,7 @@ static void rna_def_rigidbody_world(BlenderRNA *brna)
prop = RNA_def_property(srna, "constraints", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "Collection");
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK);
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK | PROP_ID_REFCOUNT);
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(
prop, "Constraints", "Collection containing rigid body constraint objects");

View File

@ -254,7 +254,7 @@ static void foreachIDLink(ModifierData *md, Object *ob, IDWalkFunc walk, void *u
}
if (clmd->sim_parms && clmd->sim_parms->effector_weights) {
walk(userData, ob, (ID **)&clmd->sim_parms->effector_weights->group, IDWALK_CB_NOP);
walk(userData, ob, (ID **)&clmd->sim_parms->effector_weights->group, IDWALK_CB_USER);
}
}

View File

@ -158,7 +158,7 @@ static void foreachIDLink(ModifierData *md, Object *ob, IDWalkFunc walk, void *u
walk(userData, ob, (ID **)&surface->brush_group, IDWALK_CB_NOP);
walk(userData, ob, (ID **)&surface->init_texture, IDWALK_CB_USER);
if (surface->effector_weights) {
walk(userData, ob, (ID **)&surface->effector_weights->group, IDWALK_CB_NOP);
walk(userData, ob, (ID **)&surface->effector_weights->group, IDWALK_CB_USER);
}
}
}

View File

@ -215,7 +215,7 @@ static void foreachIDLink(ModifierData *md, Object *ob, IDWalkFunc walk, void *u
}
if (fmd->domain->effector_weights) {
walk(userData, ob, (ID **)&fmd->domain->effector_weights->group, IDWALK_CB_NOP);
walk(userData, ob, (ID **)&fmd->domain->effector_weights->group, IDWALK_CB_USER);
}
}