Files
test/source
Nathan Vegdahl 1dcd435a87 Fix #130216: GPv3: Crash in render due to slotted Actions
The root cause of this bug can be traced to:

- `ANIM_nla_mapping_get(ac, ale)` conditionally returns an `AnimData *adt`.
- This can be `nullptr` in various cases, depending on the editor (in `ac`) and
  the type & source of data (in `ale`).
- This `nullptr` has different meanings:
  1. There is not enough information to return an `adt` (like `ac` or `ale`
     being `nullptr` themselves).
  2. NLA time remapping should not be done. For example for NLA control F-Curves
     (like animated strip influence), or Grease Pencil (because that doesn't use
     the NLA).
- The above-returned `adt` is passed to other functions. Some of them are aware
  of the "`nullptr` means no NLA time remapping" scenario, and gracefully handle
  it. Other code, however, just gets "an adt" from the caller and handles it as
  normal (and likely crashes on `nullptr`). Other cases start out as the first,
  but somewhere in the call stack shift over to the second.

The approach taken in this PR to fix the bug is to (generally) stop signaling
"do not use NLA time remapping" via `adt = nullptr`, and instead explicitly
indicate/check whether remapping should be done.

In most cases this means passing a `bAnimListElem *` instead of an `AnimData *`,
because the former has the information needed to determine if time remapping
should be done or not. However, in some cases there is no `bAnimListElem *` to
pass, and instead other information determines whether remapping is needed. In
those cases we add a `bool` parameter or field in the appropriate place so that
calling code can explicitly indicate whether remapping should be done or not.

To accomplish this a variety of functions have been added to help handle things
correctly.  Of particular note:

- `AnimData *ANIM_nla_mapping_get(ac, ale)` (that conditionally returned an
  `adt`) has been removed entirely in favor of the new
  `bool ANIM_nla_mapping_allowed(ale)` function that simply returns whether
  nla remapping should be done or not.
- `ANIM_nla_tweakedit_remap(ale, …)` has been added, which wraps
  `BKE_nla_tweakedit_remap(adt, …)` and only performs the remapping when
  `ANIM_nla_mapping_allowed()` indicates that it's allowed.
- `ANIM_nla_mapping_apply_if_needed_fcurve(ale, …)` has been added, which is an
  alternative to `ANIM_nla_mapping_apply_fcurve(adt, …)` that also only performs
  the remapping when `ANIM_nla_mapping_allowed()` indicates that it's allowed.

Note that even with this PR there are still a couple of places remaining that
use `adt = nullptr` to indicate "don't remap", because they appear to be correct
and would require larger changes to make explicit. In those cases comments have
been added to explain the situation, with a reference to this PR.  In the future
we way want to take the time to change those as well.

Also of minor note: this PR moves the definition of the type `slot_handle_t`
from ANIM_action.hh to BKE_action.hh. This is due to `BKE_nla.hh` (which needs
that definition) now being included directly and indirectly in a lot more
places. Moving the definition to BKE_action.hh prevents all of those new places
from gaining dependencies on the animrig module.

Co-authored-by: Sybren A. Stüvel <sybren@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/130440
2024-11-21 16:37:13 +01:00
..