Fix #108263: Show warning when cache baking wants to overwrite data #108288

Merged
Lukas Tönne merged 2 commits from LukasTonne/blender:warn_on_bake_dir_conflict into blender-v3.6-release 2023-06-16 10:10:27 +02:00
Member

Modifiers can use the same bake directory now. If multiple modifiers
using conflicting paths are baked at the same time there is now a
warning.

Modifiers can also bake to directories that already contain data
(including their own). To give users a heads-up there is now a
confirmation popup in that case. It only comes up once per bake operator
invoke to strike a balance between silently overwriting data and not
being too obnoxious when users want to rebake the same simulation many
times.

Modifiers can use the same bake directory now. If multiple modifiers using conflicting paths are baked at the same time there is now a warning. Modifiers can also bake to directories that already contain data (including their own). To give users a heads-up there is now a confirmation popup in that case. It only comes up once per bake operator invoke to strike a balance between silently overwriting data and not being too obnoxious when users want to rebake the same simulation many times.
Lukas Tönne requested review from Jacques Lucke 2023-05-25 19:03:10 +02:00
Lukas Tönne added this to the Nodes & Physics project 2023-05-25 19:03:19 +02:00
Lukas Tönne changed title from Show warning/confirmation when cache baking wants to overwrite data to Fix #108263: Show warning when cache baking wants to overwrite data 2023-05-25 19:40:44 +02:00
Jacques Lucke requested changes 2023-05-30 11:34:41 +02:00
@ -8,6 +8,7 @@
#include "BLI_endian_switch.h"
#include "BLI_fileops.hh"
#include "BLI_path_util.h"
#include "BLI_probing_strategies.hh"
Member

Do you really need this specific header? I would expect it to be used only by files that implement hash tables.

Do you really need this specific header? I would expect it to be used only by files that implement hash tables.
Author
Member

I needed it for the definition of the PathUsersMap below, which uses specialized string comparison for paths. I may be missing something, but i think we can only specify template arguments in order in C++17. So i need to add that ProbingStrategy parameter before i can specify the hash and equality arguments. I'd be delighted if i'm wrong!

I needed it for the definition of the `PathUsersMap` below, which uses specialized string comparison for paths. I may be missing something, but i think we can only specify template arguments in order in C++17. So i need to add that ProbingStrategy parameter before i can specify the hash and equality arguments. I'd be delighted if i'm wrong!
Author
Member

Include isn't needed any more, removed.

Include isn't needed any more, removed.
LukasTonne marked this conversation as resolved
@ -410,0 +413,4 @@
char norm_buf[256];
const size_t size = s.size() + 1;
char *norm = (size <= sizeof(norm_buf)) ? norm_buf :
static_cast<char *>(MEM_mallocN(size, __func__));
Member

Looks like this is leaking. You could use DynamicStackBuffer.

Looks like this is leaking. You could use `DynamicStackBuffer`.
LukasTonne marked this conversation as resolved
@ -410,0 +434,4 @@
}
};
static bool try_find_bake_directories(const StringRefNull absolute_bake_dir)
Member

bool bake_directory_has_data(...)

`bool bake_directory_has_data(...)`
LukasTonne marked this conversation as resolved
Lukas Tönne requested review from Jacques Lucke 2023-05-30 12:29:13 +02:00
Jacques Lucke approved these changes 2023-05-31 09:50:41 +02:00
@ -410,0 +419,4 @@
BLI_path_slash_rstrip(norm);
BLI_path_normalize(norm);
return DefaultHash<StringRef>()(norm);
Member

Can use get_default_hash.

Can use `get_default_hash`.
LukasTonne marked this conversation as resolved
@ -410,0 +465,4 @@
const char *base_path = ID_BLEND_PATH(bmain, &object->id);
LISTBASE_FOREACH (ModifierData *, md, &object->modifiers) {
if (md->type == eModifierType_Nodes) {
Member

Use early continue to avoid indentation.

Use early `continue` to avoid indentation.
LukasTonne marked this conversation as resolved
@ -410,0 +504,4 @@
for (const auto &item : path_users.items()) {
/* Check if multiple caches are writing to the same bake directory. */
if (item.value > 1) {
BKE_reportf(op->reports, RPT_WARNING, "Multiple caches baked to path %s", item.key.data());
Member

Think there should be confirmation dialog in this case as well.

Think there should be confirmation dialog in this case as well.
Author
Member

Had some discussion with @dfelinto about this issue, agreed on:

  1. Bake directory conflict should be handled as error. If we detect this there should be an error dialog and the operator won't run.
  2. After that, if the output directory already has cache data we show the confirmation dialog. Users can proceed at their discretion.

We also discussed the possibility of fixing directory paths automatically. Currently, when copying an object the bake path remains the same, leading to a path conflict. We can clear the path on copy to avoid frequent conflicts. The paths might then be auto-generated to the default on running the bake operator.
Fixing paths by appending a ".001" suffix is difficult because we don't know all the objects/modifiers that might have conflicts (e.g. in linked files). We only know a concrete set of paths to check when actually running the operator.

Had some discussion with @dfelinto about this issue, agreed on: 1. Bake directory conflict should be handled as error. If we detect this there should be an error dialog and the operator won't run. 2. After that, if the output directory already has cache data we show the confirmation dialog. Users can proceed at their discretion. We also discussed the possibility of fixing directory paths automatically. Currently, when copying an object the bake path remains the same, leading to a path conflict. We can clear the path on copy to avoid frequent conflicts. The paths might then be auto-generated to the default on running the bake operator. Fixing paths by appending a ".001" suffix is difficult because we don't know all the objects/modifiers that might have conflicts (e.g. in linked files). We only know a concrete set of paths to check when actually running the operator.
Lukas Tönne force-pushed warn_on_bake_dir_conflict from b03d67fae2 to 83cb0ccc25 2023-06-15 14:58:12 +02:00 Compare
Lukas Tönne force-pushed warn_on_bake_dir_conflict from e03ac8509d to 26e0c452ef 2023-06-15 16:30:41 +02:00 Compare
Lukas Tönne added 1 commit 2023-06-15 16:59:53 +02:00
Author
Member

This should be ready now. I'll add "clear paths on copy" in a separate patch.

Error message when paths are conflicting (operator exits):
image

Warning when bake directory contains data (continues if user confirms):
image

This should be ready now. I'll add "clear paths on copy" in a separate patch. Error message when paths are conflicting (operator exits): ![image](/attachments/59b66b24-4d48-4db7-8e9b-4f7ebe2000b6) Warning when bake directory contains data (continues if user confirms): ![image](/attachments/cd7733a0-636d-4014-8fc1-1bcbf9c01a67)

I was wondering if we do need a warning when overriding existing data. We have no warning when we do it for animation or rendering.

I was wondering if we do need a warning when overriding existing data. We have no warning when we do it for animation or rendering.
Author
Member

I was wondering if we do need a warning when overriding existing data. We have no warning when we do it for animation or rendering.

Not sure what you mean by overriding animation data.
For the render output path, a notable difference is that there is only 1 render output path, but potentially many different bake paths. Not sure what it looks like in practice, but users might have many different cache paths so it would be much easier to accidentally overwrite caches.

> I was wondering if we do need a warning when overriding existing data. We have no warning when we do it for animation or rendering. Not sure what you mean by overriding animation data. For the render output path, a notable difference is that there is only 1 render output path, but potentially many different bake paths. Not sure what it looks like in practice, but users might have many different cache paths so it would be much easier to accidentally overwrite caches.
Jacques Lucke approved these changes 2023-06-15 20:09:46 +02:00
Lukas Tönne merged commit 406a1f9bce into blender-v3.6-release 2023-06-16 10:10:27 +02:00
Lukas Tönne deleted branch warn_on_bake_dir_conflict 2023-06-16 10:10:29 +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 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#108288
No description provided.