Refactor: remove ReportList argument from insert_key #120784

Merged
Christoph Lendenfeld merged 4 commits from ChrisLend/blender:refactor_remove_reports_from_key_fn into main 2024-04-23 10:10:34 +02:00

The insert key function in animrig/keyframing.cc took a ReportList
argument which it used to print messages in case of failures.

Instead this now returns a CombinedKeyingResult and the caller is
responsible for creating reports out of that.

To make that simpler the ID argument has been changed from a pointer to a reference.
The calling functions now make sure that it's not a nullptr.

This has the effect that there will be less messages printed in the Info panel when e.g. inserting keys with a keyingset.
This still doesn't make an error message pop up though.

Before After
image image

Related to: #119776: Refactor keyframing.cc in animrig

The insert key function in `animrig/keyframing.cc` took a `ReportList` argument which it used to print messages in case of failures. Instead this now returns a `CombinedKeyingResult` and the caller is responsible for creating reports out of that. To make that simpler the `ID` argument has been changed from a pointer to a reference. The calling functions now make sure that it's not a `nullptr`. This has the effect that there will be less messages printed in the Info panel when e.g. inserting keys with a keyingset. This still doesn't make an error message pop up though. | Before | After | | - | - | | ![image](/attachments/6c021b4f-c85c-41a1-851c-54eaf0e7ea67) | ![image](/attachments/e7522128-02d8-43a2-b98f-f48e22c6deed) | Related to: [#119776: Refactor keyframing.cc in animrig](https://projects.blender.org/blender/blender/issues/119776)
Christoph Lendenfeld added the
Module
Animation & Rigging
label 2024-04-18 16:20:52 +02:00
Christoph Lendenfeld added 3 commits 2024-04-18 16:21:02 +02:00
Christoph Lendenfeld requested review from Nathan Vegdahl 2024-04-18 16:27:57 +02:00
Author
Member

@blender-bot build

@blender-bot build
Member

Failed to start build, can't connect to buildbot.

Failed to start build, can't connect to buildbot.
Nathan Vegdahl requested changes 2024-04-19 12:12:02 +02:00
Dismissed
Nathan Vegdahl left a comment
Member

Over-all looks good! Just a handful of comments.

(One thing that's a little unfortunate about this is losing the specificity about what exactly failed to get keyed, which might occasionally be useful in troubleshooting. But I think that's just a general aspect of shifting over to this style of error reporting, which overall is a big win for the common case IMO. So I still think it's good to move forward with this.)

Over-all looks good! Just a handful of comments. (One thing that's a little unfortunate about this is losing the specificity about what exactly failed to get keyed, which might occasionally be useful in troubleshooting. But I think that's just a general aspect of shifting over to this style of error reporting, which overall is a big win for the common case IMO. So I still think it's good to move forward with this.)
@ -129,1 +129,4 @@
if (this->get_count(SingleKeyingResult::ID_NOT_EDITABLE) > 0) {
const int error_count = this->get_count(SingleKeyingResult::ID_NOT_EDITABLE);
if (error_count == 1) {
Member

This pattern of printing one message if count == 1 and a different message otherwise is repeated over and over again here. So my first instinct was to try to factor that repetition out.

However, thinking about it more, I think it's likely that factoring it out wouldn't meaningfully simplify the code nor make it easier to understand or work with, and would instead just end up forcing people to jump around the file to follow the flow of the code. It's of course possible there's a good way to factor it out that I'm not thinking of, but I just wanted to leave an explicit note that as far as I can tell this particular case of repetition is probably fine as-is.

This pattern of printing one message if `count == 1` and a different message otherwise is repeated over and over again here. So my first instinct was to try to factor that repetition out. However, thinking about it more, I think it's likely that factoring it out wouldn't meaningfully simplify the code nor make it easier to understand or work with, and would instead just end up forcing people to jump around the file to follow the flow of the code. It's of course possible there's a good way to factor it out that I'm not thinking of, but I just wanted to leave an explicit note that as far as I can tell this particular case of repetition is probably fine as-is.
nathanvegdahl marked this conversation as resolved
@ -130,0 +131,4 @@
const int error_count = this->get_count(SingleKeyingResult::ID_NOT_EDITABLE);
if (error_count == 1) {
errors.append(
fmt::format("{} ID has been skipped because it is not editable.", error_count));
Member

Maybe adding "Key insertion for" at the front of these strings would be good, so if it's the only error it's still explicit in the message itself that the error was about inserting key frames.

Also, for the count == 1 case I think it reads more clearly if you just skip using fmt::format() and replace {} with an explicit "1". Seeing the {} kept making me think, "Any number can go here... wait, that would read weird with anything other than 1... oh, right".

Maybe adding "Key insertion for" at the front of these strings would be good, so if it's the only error it's still explicit in the message itself that the error was about inserting key frames. Also, for the `count == 1` case I think it reads more clearly if you just skip using `fmt::format()` and replace `{}` with an explicit "1". Seeing the `{}` kept making me think, "Any number can go here... wait, that would read weird with anything other than 1... oh, right".
Author
Member

good point about the fmt with error_count 1.
Changed it to also spell out one so it is consistent with the previous error messages.

Instead of "Key insertion for" I went with "Inserting keys for". Felt a bit easier to understand for me

good point about the `fmt` with error_count 1. Changed it to also spell out `one` so it is consistent with the previous error messages. Instead of "Key insertion for" I went with "Inserting keys for". Felt a bit easier to understand for me
nathanvegdahl marked this conversation as resolved
@ -100,6 +100,10 @@ bool autokeyframe_cfra_can_key(const Scene *scene, ID *id)
void autokeyframe_object(bContext *C, Scene *scene, Object *ob, Span<std::string> rna_paths)
{
ID *id = &ob->id;
if (id == nullptr) {
Member

I think(?) this code path will never actually be taken, unless via some weird undefined behavior: the id field is just a struct directly inside the Object type, so taking its address should never be null.

However, in theory ob itself could be null. So we can check for that. But it looks like that isn't supposed to ever happen, so I would just make an assert for it (and possibly document it as an invariant in the function's doc comment, if it isn't already). Same with the C and scene parameters, for that matter.

I think(?) this code path will never actually be taken, unless via some weird undefined behavior: the `id` field is just a struct directly inside the `Object` type, so taking its address should never be null. However, in theory `ob` itself could be null. So we can check for that. But it looks like that isn't supposed to ever happen, so I would just make an assert for it (and possibly document it as an invariant in the function's doc comment, if it isn't already). Same with the `C` and `scene` parameters, for that matter.
Author
Member

yeah you are right. In that case I'll remove the check.

yeah you are right. In that case I'll remove the check.
nathanvegdahl marked this conversation as resolved
@ -211,6 +219,10 @@ void autokeyframe_pose_channel(bContext *C,
AnimData *adt = ob->adt;
bAction *act = (adt) ? adt->action : nullptr;
if (id == nullptr) {
Member

Same here: I don't think(?) this code path is possible. Should be replaced by an assert that ob is non-null.

Same here: I don't think(?) this code path is possible. Should be replaced by an assert that `ob` is non-null.
nathanvegdahl marked this conversation as resolved
@ -271,3 +277,1 @@
&anim_eval_context,
eBezTriple_KeyframeType(ts->keyframe_type),
flag);
insert_keyframe(bmain,
Member

Do we not need to accumulate and handle the returned CombinedKeyingResult here?

Do we not need to accumulate and handle the returned `CombinedKeyingResult` here?
Author
Member

good point, the function didn't handle the return argument before, but of course now we would be missing the messages

good point, the function didn't handle the return argument before, but of course now we would be missing the messages
nathanvegdahl marked this conversation as resolved
Christoph Lendenfeld added 1 commit 2024-04-19 13:51:39 +02:00
Christoph Lendenfeld requested review from Nathan Vegdahl 2024-04-19 13:53:52 +02:00
Nathan Vegdahl approved these changes 2024-04-19 15:55:17 +02:00
Nathan Vegdahl left a comment
Member

Looks good to me!

Looks good to me!
Christoph Lendenfeld merged commit c30647a6fc into main 2024-04-23 10:10:34 +02:00
Christoph Lendenfeld deleted branch refactor_remove_reports_from_key_fn 2024-04-23 10:10:36 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
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
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
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
EEVEE & Viewport
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
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
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#120784
No description provided.