Fix #115192: Inconsistent behavior renaming data-blocks #116246

Merged
Pratik Borhade merged 2 commits from PratikPB2123/blender:115192-id-naming into main 2024-01-15 12:45:57 +01:00
Member

This is due to BLI_findstring returning wrong id from passed name.
Two IDs can have same name before making them unique so it can return
wrong id. To fix this, pass id argument instead of id_name to
BLI_libblock_ensure_unique_name and skip the use of BLI_findstring

This is due to `BLI_findstring` returning wrong id from passed name. Two IDs can have same name before making them unique so it can return wrong id. To fix this, pass id argument instead of id_name to `BLI_libblock_ensure_unique_name` and skip the use of `BLI_findstring`
Pratik Borhade added 1 commit 2023-12-16 06:20:07 +01:00
05810e0879 Fix #115192: Inconsistancy renaming datablock behaviour
This is due to `BLI_findstring` returning wrong id from passed name.
Two IDs can have same name before making them unique so it can return
wrong id. To fix this, pass id argument instead of id_name to
`BLI_libblock_ensure_unique_name` and skip the use of `BLI_findstring`
Pratik Borhade requested review from Brecht Van Lommel 2023-12-16 06:20:24 +01:00
Pratik Borhade requested review from Bastien Montagne 2023-12-16 06:20:24 +01:00
Pratik Borhade added the
Module
User Interface
label 2023-12-16 06:20:41 +01:00
Brecht Van Lommel requested changes 2023-12-18 15:03:45 +01:00
Brecht Van Lommel left a comment
Owner

A difference is that is_memfile_undo_written will now be set regardless if the name is actually changed.

I think we can now check the return value of BKE_id_new_name_validate for that, same as BKE_libblock_rename does just below.

However looking at the implementation of BKE_id_new_name_validate, it doesn't seem to account for name changes to due e.g. invalid characters. Which I think could be fixed as follows:

diff --git a/source/blender/blenkernel/intern/lib_id.cc b/source/blender/blenkernel/intern/lib_id.cc
index 2b7e57e..5956ebe 100644
--- a/source/blender/blenkernel/intern/lib_id.cc
+++ b/source/blender/blenkernel/intern/lib_id.cc
@@ -1632,6 +1632,7 @@ bool BKE_id_new_name_validate(
   }
 
   result = BKE_main_namemap_get_name(bmain, id, name, false);
+  result |= !STREQ(id->name + 2, name);
 
   BLI_strncpy(id->name + 2, name, sizeof(id->name) - 2);
   id_sort_by_name(lb, id, nullptr);
A difference is that `is_memfile_undo_written` will now be set regardless if the name is actually changed. I think we can now check the return value of `BKE_id_new_name_validate` for that, same as `BKE_libblock_rename` does just below. However looking at the implementation of `BKE_id_new_name_validate`, it doesn't seem to account for name changes to due e.g. invalid characters. Which I think could be fixed as follows: ``` diff --git a/source/blender/blenkernel/intern/lib_id.cc b/source/blender/blenkernel/intern/lib_id.cc index 2b7e57e..5956ebe 100644 --- a/source/blender/blenkernel/intern/lib_id.cc +++ b/source/blender/blenkernel/intern/lib_id.cc @@ -1632,6 +1632,7 @@ bool BKE_id_new_name_validate( } result = BKE_main_namemap_get_name(bmain, id, name, false); + result |= !STREQ(id->name + 2, name); BLI_strncpy(id->name + 2, name, sizeof(id->name) - 2); id_sort_by_name(lb, id, nullptr); ```
Pratik Borhade added 1 commit 2023-12-20 12:50:41 +01:00
Brecht Van Lommel approved these changes 2023-12-20 13:26:13 +01:00
Brecht Van Lommel left a comment
Owner

Looks good to me, but since @mont29 is owner of this code would wait for review from him too.

Looks good to me, but since @mont29 is owner of this code would wait for review from him too.

@brecht as noticed in the report (#115192), this was already reported long time ago as #71244.

Back then, there were some unclear/inconclusive discussions about whether we always want to modify the 'current' ID's name, or whether in some cases (e.g. when renaming from the UI), we'd rather change the other ID's name.

I would rather have the consistent behavior proposed by this PR as a starting point, and then evaluate whether we really need some tweaks to it (or additional operators) later, but would love to hear @ideasman42 here as well?

@brecht as noticed in the report (#115192), this was already reported long time ago as #71244. Back then, there were some [unclear/inconclusive discussions](https://projects.blender.org/blender/blender/issues/71244#issuecomment-383129) about whether we always want to modify the 'current' ID's name, or whether in some cases (e.g. when renaming from the UI), we'd rather change the other ID's name. I would rather have the consistent behavior proposed by this PR as a starting point, and then evaluate whether we really need some tweaks to it (or additional operators) later, but would love to hear @ideasman42 here as well?

I think it makes sense to allow taking the name of other datablocks from the UI. But this should then have a confirmation popup, or at least a warning in the status bar so the user can undo it. Both for individual and batch renames.

I think it makes sense to allow taking the name of other datablocks from the UI. But this should then have a confirmation popup, or at least a warning in the status bar so the user can undo it. Both for individual and batch renames.

This seems much better than the current behavior (how it should have worked all along).

The only other comment is the doc-strings in this area should be improved/clarified however that can be done as part of a separate change as they're not made invalid by this commit.

This seems much better than the current behavior (how it should have worked all along). The only other comment is the doc-strings in this area should be improved/clarified however that can be done as part of a separate change as they're not made invalid by this commit.
Campbell Barton approved these changes 2024-01-15 03:15:04 +01:00
Campbell Barton changed title from Fix #115192: Inconsistancy renaming datablock behaviour to Fix #115192: Inconsist behavior renaming data-blocks 2024-01-15 03:24:34 +01:00
Campbell Barton changed title from Fix #115192: Inconsist behavior renaming data-blocks to Fix #115192: Inconsistent behavior renaming data-blocks 2024-01-15 03:25:10 +01:00
Bastien Montagne approved these changes 2024-01-15 12:41:57 +01:00
Bastien Montagne left a comment
Owner

There is also a terrible name prefix usage here for BLI_libblock_ensure_unique_name (should be BKE_ prefix, comes from original cleanup renames 641d4e2b7f). ;)

Will fix as soon as this PR is merged.

There is also a terrible name prefix usage here for `BLI_libblock_ensure_unique_name` (should be `BKE_ prefix`, comes from original cleanup renames 641d4e2b7fc4fd). ;) Will fix as soon as this PR is merged.
Pratik Borhade merged commit 195bb4f8f5 into main 2024-01-15 12:45:57 +01:00
Pratik Borhade deleted branch 115192-id-naming 2024-01-15 12:46:00 +01:00
Author
Member

Merged, thanks for reviewing :)

Merged, thanks for reviewing :)
Sign in to join this conversation.
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
4 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#116246
No description provided.