[Bf-blender-cvs] [f1beb3b3f60] master: Cleanup: make functions for setting active/render layer more consistent

Martijn Versteegh noreply at git.blender.org
Mon May 16 16:34:39 CEST 2022


Commit: f1beb3b3f60be45854285935d6bfcedf839b317c
Author: Martijn Versteegh
Date:   Mon May 16 16:32:41 2022 +0200
Branches: master
https://developer.blender.org/rBf1beb3b3f60be45854285935d6bfcedf839b317c

Cleanup: make functions for setting active/render layer more consistent

The active/render layer is indexed from the first layer of that type. These functions
incorrectly subtracted the layer index of *each* layer, instead of the first one.
If there's only a single layer this doesn't matter, but when there are multiple layers
it will set the wrong active layer for consecutive layers.

I'm not aware of any actual errors caused by this, because the active and render layers are
only ever queried from the first layer of that type, but it was confusing during debugging a
related issue. This patch makes the behavior of CustomData_set_layer_active_index()
consistent with CustomData_set_layer_active() and the same for render.

Differential Revision: https://developer.blender.org/D14955

===================================================================

M	source/blender/blenkernel/intern/customdata.cc

===================================================================

diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc
index 62351a31042..52d2060a1fc 100644
--- a/source/blender/blenkernel/intern/customdata.cc
+++ b/source/blender/blenkernel/intern/customdata.cc
@@ -2575,18 +2575,24 @@ void CustomData_set_layer_stencil(CustomData *data, int type, int n)
 
 void CustomData_set_layer_active_index(CustomData *data, int type, int n)
 {
+  const int layer_index = data->typemap[type];
+  BLI_assert(customdata_typemap_is_valid(data));
+
   for (int i = 0; i < data->totlayer; i++) {
     if (data->layers[i].type == type) {
-      data->layers[i].active = n - i;
+      data->layers[i].active = n - layer_index;
     }
   }
 }
 
 void CustomData_set_layer_render_index(CustomData *data, int type, int n)
 {
+  const int layer_index = data->typemap[type];
+  BLI_assert(customdata_typemap_is_valid(data));
+
   for (int i = 0; i < data->totlayer; i++) {
     if (data->layers[i].type == type) {
-      data->layers[i].active_rnd = n - i;
+      data->layers[i].active_rnd = n - layer_index;
     }
   }
 }



More information about the Bf-blender-cvs mailing list