Simplified GRAPH_OT_driver_delete_invalid after feedback @aligorith

By adding the ANIMFILTER_NODUPLIS flag to the filter it'll only be
processing each F-Curve once, which means we can remove while iterating.

This also solves a potential issue when a datablock has a driver and is
shared among multiple objects.
This commit is contained in:
Sybren A. Stüvel 2018-01-17 12:38:14 +01:00
parent c38ebf93e3
commit 0aaae43748
1 changed files with 2 additions and 20 deletions

View File

@ -2746,19 +2746,12 @@ void GRAPH_OT_driver_variables_paste(wmOperatorType *ot)
}
/* ************************************************************************** */
typedef struct InvalidDriverInfo {
struct InvalidDriverInfo *next, *prev;
ID *id;
FCurve *fcu;
} InvalidDriverInfo;
static int graph_driver_delete_invalid_exec(bContext *C, wmOperator *op)
{
bAnimContext ac;
ListBase anim_data = {NULL, NULL};
ListBase to_delete = {NULL, NULL};
bAnimListElem *ale;
InvalidDriverInfo *idi;
int filter;
bool ok = false;
unsigned int deleted = 0;
@ -2770,7 +2763,7 @@ static int graph_driver_delete_invalid_exec(bContext *C, wmOperator *op)
/* NOTE: we might need a scene update to evaluate the driver flags */
/* filter data */
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE);
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS);
ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
/* find invalid drivers */
@ -2783,17 +2776,7 @@ static int graph_driver_delete_invalid_exec(bContext *C, wmOperator *op)
continue;
}
/* remember in a separate list so we don't iterate over the same collection we modify */
idi = MEM_callocN(sizeof(InvalidDriverInfo), "invalid driver info");
BLI_assert(idi != NULL);
idi->id = ale->id;
idi->fcu = fcu;
BLI_addtail(&to_delete, idi);
}
/* delete invalid drivers */
for (idi = to_delete.first; idi; idi = idi->next) {
ok |= ANIM_remove_driver(op->reports, idi->id, idi->fcu->rna_path, idi->fcu->array_index, 0);
ok |= ANIM_remove_driver(op->reports, ale->id, fcu->rna_path, fcu->array_index, 0);
if (!ok) {
break;
}
@ -2801,7 +2784,6 @@ static int graph_driver_delete_invalid_exec(bContext *C, wmOperator *op)
}
/* cleanup */
BLI_freelistN(&to_delete);
ANIM_animdata_freelist(&anim_data);
if (deleted > 0) {