Files
test2/source/blender/animrig/intern/anim_rna.cc
Christoph Lendenfeld bf96f6cda9 Fix: failing unit tests due to "stack-use-after-scope"
The return value of `get_rotation_mode_path` was stored in a
`blender::StringRef` which caused the memory of the string to
be freed to early.

Fix by returning a `blender::StringRef`

Interestingly this seems to be only an issue on ASAN builds.

Pull Request: https://projects.blender.org/blender/blender/pulls/116434
2023-12-21 19:40:45 +01:00

85 lines
2.2 KiB
C++

/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup animrig
*/
#include "ANIM_rna.hh"
#include "BLI_vector.hh"
#include "DNA_action_types.h"
#include "RNA_access.hh"
namespace blender::animrig {
Vector<float> get_rna_values(PointerRNA *ptr, PropertyRNA *prop)
{
Vector<float> values;
if (RNA_property_array_check(prop)) {
const int length = RNA_property_array_length(ptr, prop);
switch (RNA_property_type(prop)) {
case PROP_BOOLEAN: {
bool *tmp_bool = static_cast<bool *>(MEM_malloc_arrayN(length, sizeof(bool), __func__));
RNA_property_boolean_get_array(ptr, prop, tmp_bool);
for (int i = 0; i < length; i++) {
values.append(float(tmp_bool[i]));
}
MEM_freeN(tmp_bool);
break;
}
case PROP_INT: {
int *tmp_int = static_cast<int *>(MEM_malloc_arrayN(length, sizeof(int), __func__));
RNA_property_int_get_array(ptr, prop, tmp_int);
for (int i = 0; i < length; i++) {
values.append(float(tmp_int[i]));
}
MEM_freeN(tmp_int);
break;
}
case PROP_FLOAT: {
values.reinitialize(length);
RNA_property_float_get_array(ptr, prop, &values[0]);
break;
}
default:
values.reinitialize(length);
break;
}
}
else {
switch (RNA_property_type(prop)) {
case PROP_BOOLEAN:
values.append(float(RNA_property_boolean_get(ptr, prop)));
break;
case PROP_INT:
values.append(float(RNA_property_int_get(ptr, prop)));
break;
case PROP_FLOAT:
values.append(RNA_property_float_get(ptr, prop));
break;
case PROP_ENUM:
values.append(float(RNA_property_enum_get(ptr, prop)));
break;
default:
values.append(0.0f);
}
}
return values;
}
StringRef get_rotation_mode_path(const eRotationModes rotation_mode)
{
switch (rotation_mode) {
case ROT_MODE_QUAT:
return "rotation_quaternion";
case ROT_MODE_AXISANGLE:
return "rotation_axis_angle";
default:
return "rotation_euler";
}
}
} // namespace blender::animrig