Anim: remove strip data as well when an action strip is removed #127837

Merged
Nathan Vegdahl merged 9 commits from nathanvegdahl/blender:strip_data_removal into main 2024-09-20 13:07:30 +02:00
Member

This is a follow up to #126559. In that PR, strip data is never deleted even
when the strip that uses it is. Thus, the strip data array just keeps growing as
more strips are added, and never shrinks.

This PR implements that deletion. The approach is simple: remove the strip data
from the array using a swap-remove that swaps in the last item in the data
array, and then loop over the strips in the action to update any that were
referencing that swapped-in item. Additionally, before removal we check to make
sure the data item isn't still being used by any strips, and if it is then we
don't remove it.

This is a follow up to #126559. In that PR, strip data is never deleted even when the strip that uses it is. Thus, the strip data array just keeps growing as more strips are added, and never shrinks. This PR implements that deletion. The approach is simple: remove the strip data from the array using a swap-remove that swaps in the last item in the data array, and then loop over the strips in the action to update any that were referencing that swapped-in item. Additionally, before removal we check to make sure the data item isn't still being used by any strips, and if it is then we don't remove it.
Nathan Vegdahl added the
Module
Animation & Rigging
label 2024-09-19 10:16:55 +02:00
Nathan Vegdahl added 1 commit 2024-09-19 10:17:06 +02:00
WIP, because I still need to flesh out the unit tests.
Nathan Vegdahl added 1 commit 2024-09-19 11:44:21 +02:00
Nathan Vegdahl added 1 commit 2024-09-19 11:58:11 +02:00
Nathan Vegdahl added 1 commit 2024-09-19 12:07:41 +02:00
Nathan Vegdahl added 1 commit 2024-09-19 12:14:38 +02:00
Nathan Vegdahl added 1 commit 2024-09-19 12:33:14 +02:00
Nathan Vegdahl changed title from WIP: Anim: remove strip data as well when an action strip is removed to Anim: remove strip data as well when an action strip is removed 2024-09-19 12:36:53 +02:00
Nathan Vegdahl requested review from Sybren A. Stüvel 2024-09-19 12:37:03 +02:00
Nathan Vegdahl requested review from Christoph Lendenfeld 2024-09-19 12:37:16 +02:00
Nathan Vegdahl added 1 commit 2024-09-19 14:00:15 +02:00
Christoph Lendenfeld reviewed 2024-09-19 16:07:54 +02:00
Christoph Lendenfeld left a comment
Member

lgtm

on a general note I am not super happy that the action has to be friends with the Strip and the Layer but I don't see that as critical

lgtm on a general note I am not super happy that the action has to be friends with the Strip and the Layer but I don't see that as critical
@ -146,0 +148,4 @@
* elements after the removed item over to fill the gap, it just swaps in the last
* element to where the removed element was.
*/
template<typename T> static void shrink_array_and_swap_remove(T **array, int *num, const int index)

I am a bit surprised those functions don't exist somewhere in Blender already. They seem very generic

I am a bit surprised those functions don't exist somewhere in Blender already. They seem very generic
Author
Member

Yeah, these should be moved to DNA_array_utils.hh at some point, so they can be used throughout the code base. Might be a good thing for me to tackle as part of my work in Q4?

Yeah, these should be moved to `DNA_array_utils.hh` at some point, so they can be used throughout the code base. Might be a good thing for me to tackle as part of my work in Q4?
Christoph Lendenfeld approved these changes 2024-09-19 16:08:04 +02:00
Sybren A. Stüvel approved these changes 2024-09-20 11:49:03 +02:00
Sybren A. Stüvel left a comment
Member

LGTM, with a few small notes that can be handled when landing.

LGTM, with a few small notes that can be handled when landing.
@ -360,0 +375,4 @@
*
* \return True on success, false on failure.
*/
bool strip_keyframe_data_remove(int index);

Rename to strip_keyframe_data_remove_if_unused() because otherwise I'd definitely expect it to always remove.

Rename to `strip_keyframe_data_remove_if_unused()` because otherwise I'd definitely expect it to always remove.
nathanvegdahl marked this conversation as resolved
@ -875,3 +935,4 @@
return false;
}
const Strip::Type strip_type = this->strip(strip_index)->type();

If it's already known that strip has that index, why do you do two lookups again? Why not use strip->type() and strip->data_index here?

If it's already known that `strip` has that index, why do you do two lookups again? Why not use `strip->type()` and `strip->data_index` here?
Author
Member

Because I'm a goofball!

Thanks. :-)

Because I'm a goofball! Thanks. :-)
nathanvegdahl marked this conversation as resolved
@ -878,3 +941,4 @@
dna::array::remove_index(
&this->strip_array, &this->strip_array_num, nullptr, strip_index, strip_ptr_destructor);
switch (strip_type) {

Add a comment that things are done in this order because otherwise strip_keyframe_data_remove() will still see the to-be-removed strip as a user of the data, and not do anything.

Add a comment that things are done in this order because otherwise `strip_keyframe_data_remove()` will still see the to-be-removed strip as a user of the data, and not do anything.
nathanvegdahl marked this conversation as resolved
@ -880,1 +943,4 @@
switch (strip_type) {
case Strip::Type::Keyframe:
owning_action.strip_keyframe_data_remove(data_index);

Why is this function returning a bool if it's ignored in the only call site? It's probably clearer once the function is renamed, because then the "if unused" part is more obvious.

Why is this function returning a `bool` if it's ignored in the only call site? It's probably clearer once the function is renamed, because then the "if unused" part is more obvious.
Author
Member

Yeah, it's not necessary, but seemed like reasonable information to provide to the caller. But you're right, better to keep the API to what's actually used. It's easy to add the return value back in the future if it ends up actually being needed for something.

Yeah, it's not necessary, but seemed like reasonable information to provide to the caller. But you're right, better to keep the API to what's actually used. It's easy to add the return value back in the future if it ends up actually being needed for something.
nathanvegdahl marked this conversation as resolved
Nathan Vegdahl added 1 commit 2024-09-20 12:03:09 +02:00
Nathan Vegdahl added 1 commit 2024-09-20 12:18:25 +02:00
Address PR comments
All checks were successful
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
99ce36f5d5
Author
Member

@blender-bot build

@blender-bot build
Nathan Vegdahl merged commit b200d1f975 into main 2024-09-20 13:07:30 +02:00
Nathan Vegdahl deleted branch strip_data_removal 2024-09-20 13:07:38 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#127837
No description provided.