Page MenuHome

Constraints: introduce wrapper functions to access target lists.
ClosedPublic

Authored by Alexander Gavrilov (angavrilov) on Jan 16 2022, 7:50 PM.

Details

Summary

Instead of directly accessing constraint-specific callbacks
in code all over blender, introduce two wrappers to retrieve
and free the target list.

This incidentally revealed a place within the Collada exporter
in BCAnimationSampler.cpp that didn't clean up after retrieving
the targets, resulting in a small memory leak. Fixing this should
be the only functional change in this commit.

This was split off from D9732.

Diff Detail

Repository
rB Blender

Event Timeline

Alexander Gavrilov (angavrilov) requested review of this revision.Jan 16 2022, 7:50 PM
Alexander Gavrilov (angavrilov) created this revision.

Rebased and fixed conflict.

Sybren A. Stüvel (sybren) requested changes to this revision.Feb 18 2022, 2:47 PM

This is some nice cleanup, I agree that it's desirable to have functions for this.

source/blender/blenkernel/BKE_constraint.h
315

Document the return value.

315

Document that r_list is appended to by this function, and not cleared.

320

Document what type should be in list.

320

Name list after the thing in there. The fact that it's a ListBase already communicates that this is a list.

320

I'm not a fan of boolean parameters, and even less of inverted boolean parameters. This should at least document what happens when it's true/false. It would be even better to just have two separate functions, one for copying and one for not, if that's in any way doable. They can then get their own documentation.

source/blender/blenkernel/intern/constraint.c
6198

Flip the condition, return early. Same for the other ones, so that the happy flow is going straight down instead of indenting more and more.

This revision now requires changes to proceed.Feb 18 2022, 2:47 PM
Alexander Gavrilov (angavrilov) marked 5 inline comments as done.Feb 21 2022, 7:47 PM
Alexander Gavrilov (angavrilov) added inline comments.
source/blender/blenkernel/BKE_constraint.h
315

Actually, there is no reason not to clear it - it's just an artifact of how things worked before.

320

The parameter is directly inherited from the original callback, so parameters in the calls to the wrapper look the same.

Two tiny changes, no need to re-review after this.

source/blender/blenkernel/intern/constraint.c
6195–6197

Use BLI_listbase_clear().

6204–6211

Simplify:

/* Constraint-specific targets. */
if (cti->get_constraint_targets == NULL) {
  return 0;
}
return cti->get_constraint_targets(con, r_targets);
This revision is now accepted and ready to land.Jun 3 2022, 2:38 PM
Alexander Gavrilov (angavrilov) marked an inline comment as done.Jun 3 2022, 3:15 PM
Alexander Gavrilov (angavrilov) added inline comments.
source/blender/blenkernel/intern/constraint.c
6204–6211

It's written this way so a further planned patch (as mentioned this is a part of D9732 split off to simplify review, and I will immediately rebase that one after committing) can simply insert some code without refactoring it again.