Fix #135711: Setting Grease Pencil modifier materials are not refcounted
When setting these materials, then removing the modifier, usercount would be decreased, resulting in possible dataloss on reload Affected were: - all Grease Pencil modifiers material influence materials - `LineartModifier` `target_material` - `OutlineModifier` `outline_material` These were all using `IDWALK_CB_USER` which ends up decrementing usercount in `modifier_free_data_id_us_cb` when the modifier is removed So to resolve, decrement/increment material usercount in `rna_GreasePencilModifier_material_set` appropriately NOTE: previously, it was also doing `id_lib_extern` on the object?! (should be on the material, no?) NOTE: still not 100% sure where we actually use refcounting (esp. in modifiers) and where we dont, another alternative is to just drop it and use IDWALK_CB_NOP` (instead of `IDWALK_CB_USER`) for these materials. Pull Request: https://projects.blender.org/blender/blender/pulls/135729
This commit is contained in:
committed by
Falk David
parent
2c4628c474
commit
1f780a5caa
@@ -2101,10 +2101,15 @@ static void rna_GreasePencilModifier_material_set(PointerRNA *ptr,
|
||||
Material **ma_target)
|
||||
{
|
||||
Object *ob = reinterpret_cast<Object *>(ptr->owner_id);
|
||||
Material *ma_old = *ma_target;
|
||||
Material *ma = reinterpret_cast<Material *>(value.data);
|
||||
|
||||
if (ma == nullptr || BKE_object_material_index_get(ob, ma) != -1) {
|
||||
id_lib_extern(reinterpret_cast<ID *>(ob));
|
||||
id_us_min(&ma_old->id);
|
||||
id_us_plus_no_lib(&ma->id);
|
||||
if (!ID_IS_LINKED(&ob->id)) {
|
||||
id_lib_extern(&ma->id);
|
||||
}
|
||||
*ma_target = ma;
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user