Page MenuHome

Refactor: Add CustomData_set_layer_name_index(CD, index , newname) to have a single place to do everything needed on layer renames.
AbandonedPublic

Authored by Martijn Versteegh (Baardaap) on May 20 2022, 12:02 PM.

Details

Summary

No functional changes.

This is also in preparation to possible renaming of associated data layers in the future.

This changes the functionality of CustomData_set_layer_name(), because it now calls
CustomData_set_unique_name() on every name change, while that function didn't do
that before. However at the current moment CustomData_set_layer_name() is used only
once, in versioning_270.c, to correct a faulty CD_MDEFORMVERT layer. As
CustomData_set_unique_name() ignores CD_MDEFORMVERT layers because they don't
have a LayerTypeInfo.defaultname this is no problem.

Diff Detail

Repository
rB Blender
Branch
arcpatch-D14995 (branched from master)
Build Status
Buildable 22407
Build 22407: arc lint + arc unit

Event Timeline

Martijn Versteegh (Baardaap) requested review of this revision.May 20 2022, 12:02 PM
Martijn Versteegh (Baardaap) created this revision.

I have a small doubt about how to handle the existing CustomData_set_layer_name(CD, type, n, newname).

  • On the one hand I think it would be more consistent to make that function call back to the new CustomData_set_layer_name_index().
  • On the other hand this might/would (can't completely oversee) change the behaviour in the single place it is used, versioning_270.c , where it is used to set the name of some layer to an empty string. Making it use the new function would cause CustomData_set_layer_unique_name() to be called on that layer as well, which sets a default name if an empty string is specified. I don't really understand (yet) if this would be bad.

Make CustomData_set_layer_name() also use the new CustomData_set_layer_name_index().

Not doing so would lead to there *still* being multiple paths to rename
layers. The *might* influence the only place this functions was called up
till now: versioning_270.c , fix for T51520 where a faulty layer name is
cleared. Now CustomData_set_layer_unique_name() gets called on the empty
layer. Which I *think* is ok, but I'm not sure.

Martijn Versteegh (Baardaap) retitled this revision from Add CustomData_set_layer_name_index(CD, index , newname) to have a single place to do everything needed on layer renames. to Refactor: Add CustomData_set_layer_name_index(CD, index , newname) to have a single place to do everything needed on layer renames..May 24 2022, 9:44 AM
Martijn Versteegh (Baardaap) edited the summary of this revision. (Show Details)
  • Remove incorrect const.

I think this refactor makes sense. For a proper attribute API, I think the function would just have an old name and new name argument, but that doesn't make sense for CustomData.

However, I think the current use of the function in versioning code probably shouldn't go through this code path, in case it's changed further in the future.
Since the versioning code has access to all the struct definitions, it could just find the layer and write to the name directly.

source/blender/blenkernel/BKE_customdata.h
403

Given the second sentence, I'm not sure what "Unconditionally" means here.

Like it is now the versioning code doesn't mind the new codepath, since it has no effect on the type of layer in question.

But maybe letting it write directly to the name would be better indeed, just to be on the safe side.

source/blender/blenkernel/BKE_customdata.h
403

I mean it can't fail because the layer doesn't exist or something. No error checking is done on the layer existing or not.

That's maybe badly worded I'll try to think of a better way.

  • Remove confusing 'unconditionally'.
  • Let the versioningcode directly write to the layername and not use CustomData_set_layer_name()
  • Merge branch 'master' into singlelayerrename
Martijn Versteegh (Baardaap) marked an inline comment as done.Jun 1 2022, 7:40 PM

I changed the versioning code to just directly clear the name, without going through CustomData_set_layer_name()

Looks better to me, thanks! Just a small comment

source/blender/blenloader/intern/versioning_270.c
1603

Shouldn't we check if the index is -1 here?

  • Check index is not -1 and add assert.
Martijn Versteegh (Baardaap) marked an inline comment as done.Jun 2 2022, 10:53 AM
Martijn Versteegh (Baardaap) added inline comments.
source/blender/blenloader/intern/versioning_270.c
1603

whoops! I think you're right.

Great!

source/blender/blenloader/intern/versioning_270.c
1602

I'll make this const int when committing :)

This revision is now accepted and ready to land.Jun 2 2022, 10:55 AM
Martijn Versteegh (Baardaap) marked an inline comment as done.
  • add const
Martijn Versteegh (Baardaap) marked an inline comment as done.
  • Fix wrong assert.

As discussed with @Hans Goudey (HooglyBoogly) , the current renaming doesn't take into account cross-domain name uniqueness. Because fixing that would mean rewriting this again it's better to fix that problem at the same time.

source/blender/blenloader/intern/versioning_270.c
1602

added it anyway ;-)