Fix usercount not decrementing in `gpencil_stroke_separate_exec`

This is part of T79273 where separating a stroke would result in
multiuser gpencil data for the original object.
Real underlying issue seems to be that gpencil multiuser objects (also
the ones created by Alt+D duplicating) have a problem evaluating
modifiers correctly [this will need further investigation].
Not sure if this is a limitation of D5470?

This patch only corrects the usercount on separating [which already fixes
the scenario reported because singleuser gpencil modifiers work
correctly].

Note: we could have also called `ED_object_add_duplicate` with the
`USER_DUP_GPENCIL` dupflag -- that would have taken care of the usercount
--, but then the whole following logic in `gpencil_stroke_separate_exec`
would need to change from **adding** layers/frames/strokes to
**removing** these.

Part of T79273

Maniphest Tasks: T79273

Differential Revision: https://developer.blender.org/D8419
This commit is contained in:
Philipp Oeser 2020-07-29 12:53:49 +02:00 committed by Jeroen Bakker
parent 2c68c92524
commit ee43580623
Notes: blender-bot 2023-03-24 17:05:22 +01:00
Referenced by issue #79273, GPencil: Modifiers don't work after separate strokes and use hide in outliner [issue with multiuser gpencil objects and modifiers]
Referenced by issue #77348, Blender LTS: Maintenance Task 2.83
1 changed files with 4 additions and 1 deletions

View File

@ -4251,8 +4251,11 @@ static int gp_stroke_separate_exec(bContext *C, wmOperator *op)
base_new = ED_object_add_duplicate(bmain, scene, view_layer, base_prev, dupflag);
ob_dst = base_new->object;
ob_dst->mode = OB_MODE_OBJECT;
/* create new grease pencil datablock */
/* Duplication will increment bGPdata usercount, but since we create a new greasepencil datablock
* for ob_dst (which gets its own user automatically), we have to decrement the usercount again.
*/
gpd_dst = BKE_gpencil_data_addnew(bmain, gpd_src->id.name + 2);
id_us_min(ob_dst->data);
ob_dst->data = (bGPdata *)gpd_dst;
/* loop old datablock and separate parts */