Fix #103410: name collisions between vertex groups and attributes #109910

Merged
Philipp Oeser merged 8 commits from lichtwerk/blender:103410 into main 2023-08-08 10:11:18 +02:00
Member

These name collisions should be avoided with attributes, all sorts of
issues can arise from those. We already warned in the attributes
(but not the vertex groups) list if those were found.

Previously, creating a vertex group with the same name as an already
existing attribute would allow this (and give said warning), and creating
an attribute with the same name as an already existing vertex group
would silently fail (as in: not return a layer) -- and then due to an oversight
in 101d04f41f (which assumed a valid layer would always be returned
by BKE_id_attribute_new) would even crash.

Now name collisions between vertex groups and attributes are avoided,
unique names will be found across attributes and vertex groups if either
BKE_id_attribute_calc_unique_name or BKE_object_defgroup_unique_name
is called.

This is done by unifying the checks and callbacks for both into a single.

These name collisions should be avoided with attributes, all sorts of issues can arise from those. We already warned in the attributes (but not the vertex groups) list if those were found. Previously, creating a vertex group with the same name as an already existing attribute would allow this (and give said warning), and creating an attribute with the same name as an already existing vertex group would silently fail (as in: not return a layer) -- and then due to an oversight in 101d04f41f (which assumed a valid layer would always be returned by `BKE_id_attribute_new`) would even crash. Now name collisions between vertex groups and attributes are avoided, unique names will be found across attributes and vertex groups if either `BKE_id_attribute_calc_unique_name` or `BKE_object_defgroup_unique_name` is called. This is done by unifying the checks and callbacks for both into a single.
Philipp Oeser added 1 commit 2023-07-10 14:59:18 +02:00
These name collisions should be avoided with customdata, all sorts of
issues can arise from those.
We already warned in the attributes (but not the vertex groups) list if
those were found.
Previously, creating a vertex group with the same name as an already
existing attribute would allow this (and give said warning).
Previously, creating an attribute with the same name as an already
existing vertex group would silently fail (as in: dont return a layer)
-- and then due to an oversight in 101d04f41f (which assumed a valid
layer would always be returned by `BKE_id_attribute_new` and would
access stuff in the NULL layer) would even crash.

Now name collisions between vertex groups and attributes are handled by
ensuring unique names correctly.
This is done by running `BLI_uniquename_cb` twice (onnce for attributes
and once for vertex groups) -- doing this in one callback is probably
not possible since we would run into recursive infinite loops between the
two (at least afaict).
Philipp Oeser requested review from Hans Goudey 2023-07-10 14:59:33 +02:00
Philipp Oeser requested review from Brecht Van Lommel 2023-07-10 14:59:39 +02:00
Philipp Oeser added this to the Core project 2023-07-10 14:59:47 +02:00
Philipp Oeser added the
Interest
Modeling
Interest
Animation & Rigging
labels 2023-07-10 15:00:06 +02:00
Author
Member

Hrmf, just noticed this can still produce non-uniques..., probably better to stick into a single callback after all, will check again...

Hrmf, just noticed this can still produce non-uniques..., probably better to stick into a single callback after all, will check again...
Philipp Oeser changed title from Fix #103410: name collisions between vertex groups and attributes to WIP: Fix #103410: name collisions between vertex groups and attributes 2023-07-10 15:41:02 +02:00

Can you describe the behavior, "handled by ensuring unique names correctly" is not clear to me.

Does it refuse to rename? Rename the item being edited? Rename another item?

Can you describe the behavior, "handled by ensuring unique names correctly" is not clear to me. Does it refuse to rename? Rename the item being edited? Rename another item?
Philipp Oeser added 1 commit 2023-07-14 13:13:48 +02:00
Philipp Oeser added 1 commit 2023-07-14 13:22:52 +02:00
Author
Member

Can you describe the behavior, "handled by ensuring unique names correctly" is not clear to me.

Does it refuse to rename? Rename the item being edited? Rename another item?

Unique names will be found across attributes and vertex groups if either BKE_id_attribute_calc_unique_name or BKE_object_defgroup_unique_name is called, so renaming will always be possible, who's name is being changed depends on how the two functions are called [but should be mostly done on the currently edited entiy afaict]

> Can you describe the behavior, "handled by ensuring unique names correctly" is not clear to me. > > Does it refuse to rename? Rename the item being edited? Rename another item? Unique names will be found across attributes and vertex groups if either `BKE_id_attribute_calc_unique_name` or `BKE_object_defgroup_unique_name` is called, so renaming will always be possible, who's name is being changed depends on how the two functions are called [but should be mostly done on the currently edited entiy afaict]
Philipp Oeser changed title from WIP: Fix #103410: name collisions between vertex groups and attributes to Fix #103410: name collisions between vertex groups and attributes 2023-07-14 13:24:54 +02:00
Hans Goudey requested changes 2023-07-14 14:26:54 +02:00
Hans Goudey left a comment
Member

Thanks, this seems generally reasonable.

Thanks, this seems generally reasonable.
@ -10,2 +10,4 @@
#pragma once
#include "DNA_ID.h"
#include "DNA_object_types.h"
Member

These includes should be unnecessary with forward declarations. It's good to avoid including headers in headers where possible, especially for such a common file such as BKE_attribute.h.

These includes should be unnecessary with forward declarations. It's good to avoid including headers in headers where possible, especially for such a common file such as `BKE_attribute.h`.
lichtwerk marked this conversation as resolved
@ -22,6 +25,11 @@ struct CustomDataLayer;
struct ID;
struct ReportList;
typedef struct AttributeAndDefgroupUniqueNameData {
Member

It might be nicer to define this right above BKE_id_attribute_and_defgroup_unique_name_check, leaving the top of the file for more generally used / important things like the attribute domain enum definition.

It might be nicer to define this right above `BKE_id_attribute_and_defgroup_unique_name_check`, leaving the top of the file for more generally used / important things like the attribute domain enum definition.
lichtwerk marked this conversation as resolved
@ -233,0 +229,4 @@
AttributeAndDefgroupUniqueNameData *data = static_cast<AttributeAndDefgroupUniqueNameData *>(
arg);
/* Checking vertex groups first. */
Member

This comment basically says the same thing that the BKE_defgroup_unique_name_check function name does. Best to let the code do the talking here I think-- comments can describe the reasoning, etc. but just saying what the code does on the next line usually shouldn't be necessary

This comment basically says the same thing that the `BKE_defgroup_unique_name_check` function name does. Best to let the code do the talking here I think-- comments can describe the reasoning, etc. but just saying what the code does on the next line usually shouldn't be necessary
lichtwerk marked this conversation as resolved
@ -447,6 +448,9 @@ bool BKE_object_supports_vertex_groups(const Object *ob)
const ListBase *BKE_id_defgroup_list_get(const ID *id)
{
switch (GS(id->name)) {
case ID_OB: {
Member

This function is meant to be called on object data, adding this is misleading compared to the other cases IMO

This function is meant to be called on object data, adding this is misleading compared to the other cases IMO
lichtwerk marked this conversation as resolved

Unique names will be found across attributes and vertex groups if either BKE_id_attribute_calc_unique_name or BKE_object_defgroup_unique_name is called, so renaming will always be possible, who's name is being changed depends on how the two functions are called [but should be mostly done on the currently edited entiy afaict]

Is it mostly or always? And if not always, when is it renaming another item?

If for example you rename an attribute and then it changes a vertex group name that would be a problem.

> Unique names will be found across attributes and vertex groups if either `BKE_id_attribute_calc_unique_name` or `BKE_object_defgroup_unique_name` is called, so renaming will always be possible, who's name is being changed depends on how the two functions are called [but should be mostly done on the currently edited entiy afaict] Is it mostly or always? And if not always, when is it renaming another item? If for example you rename an attribute and then it changes a vertex group name that would be a problem.
Author
Member

Unique names will be found across attributes and vertex groups if either BKE_id_attribute_calc_unique_name or BKE_object_defgroup_unique_name is called, so renaming will always be possible, who's name is being changed depends on how the two functions are called [but should be mostly done on the currently edited entiy afaict]

Is it mostly or always? And if not always, when is it renaming another item?

If for example you rename an attribute and then it changes a vertex group name that would be a problem.

Checking the current usages of the two, I dont see how that could happen, seems to always use the unique name on the entity being edited

> > Unique names will be found across attributes and vertex groups if either `BKE_id_attribute_calc_unique_name` or `BKE_object_defgroup_unique_name` is called, so renaming will always be possible, who's name is being changed depends on how the two functions are called [but should be mostly done on the currently edited entiy afaict] > > Is it mostly or always? And if not always, when is it renaming another item? > > If for example you rename an attribute and then it changes a vertex group name that would be a problem. Checking the current usages of the two, I dont see how that could happen, seems to always use the unique name on the entity being edited
Philipp Oeser added 2 commits 2023-07-14 15:33:49 +02:00
Philipp Oeser requested review from Hans Goudey 2023-07-14 15:35:13 +02:00

Ok, that's fine then.

Ok, that's fine then.
Hans Goudey reviewed 2023-07-14 17:01:12 +02:00
@ -119,1 +119,4 @@
typedef struct AttributeAndDefgroupUniqueNameData {
struct ID *id;
struct bDeformGroup *dg;
Member

This should be forward declared at the top of the file right before CustomData

This should be forward declared at the top of the file right before `CustomData`
lichtwerk marked this conversation as resolved
@ -303,1 +308,4 @@
const int index = CustomData_get_named_layer_index(customdata, type, uniquename);
if (index == -1) {
BKE_reportf(
reports, RPT_WARNING, "Layer '%s' could not be created with a unique name", uniquename);
Member

"with a unique name" seems a bit off here, a bit like unnecessary information-- there are other things that could go wrong. And actually the unique name seems like one thing that generally shouldn't fail? When do you run into this in practice?

"with a unique name" seems a bit off here, a bit like unnecessary information-- there are other things that could go wrong. And actually the unique name seems like one thing that generally shouldn't fail? When do you run into this in practice?
Author
Member

Yep, this was from the very first iteration where I didnt actually have the real solution implemented...

Yep, this was from the very first iteration where I didnt actually have the real solution implemented...
lichtwerk marked this conversation as resolved
Philipp Oeser added 1 commit 2023-07-15 13:47:23 +02:00
Hans Goudey approved these changes 2023-07-24 21:25:02 +02:00
@ -715,0 +722,4 @@
sizeof(dg->name));
}
else {
AttributeAndDefgroupUniqueNameData data{&ob->id, dg};
Member

AttributeAndDefgroupUniqueNameData data{static_cast<ID *>(ob->data), dg};

This removes the need for the change in defgroup_find_name_dupe

`AttributeAndDefgroupUniqueNameData data{static_cast<ID *>(ob->data), dg};` This removes the need for the change in `defgroup_find_name_dupe`

The design is fine, I don't think I need to review the implementation.

The design is fine, I don't think I need to review the implementation.
Brecht Van Lommel refused to review 2023-07-25 15:06:25 +02:00
Philipp Oeser added 2 commits 2023-08-08 10:00:41 +02:00
avoids a distinction in `defgroup_find_name_dupe`
Philipp Oeser merged commit 12ef20990b into main 2023-08-08 10:11:18 +02:00
Philipp Oeser deleted branch 103410 2023-08-08 10:11:19 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
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
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
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#109910
No description provided.