From f1beb3b3f60be45854285935d6bfcedf839b317c Mon Sep 17 00:00:00 2001 From: Martijn Versteegh Date: Mon, 16 May 2022 16:32:41 +0200 Subject: 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 --- source/blender/blenkernel/intern/customdata.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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; } } } -- cgit v1.2.3