Fix #132606: ActionSlots can be created with too long names
The max length of the RNA property `ActionSlot.identifier` was set incorrectly. The setter code did manage the length properly, but the getter was checking agains that incorrect max length, and rightfully complained. Pull Request: https://projects.blender.org/blender/blender/pulls/132691
This commit is contained in:
@@ -1987,7 +1987,7 @@ static void rna_def_action_slot(BlenderRNA *brna)
|
||||
prop = RNA_def_property(srna, "identifier", PROP_STRING, PROP_NONE);
|
||||
RNA_def_struct_name_property(srna, prop);
|
||||
RNA_def_property_string_funcs(prop, nullptr, nullptr, "rna_ActionSlot_identifier_set");
|
||||
RNA_def_property_string_maxlength(prop, sizeof(ActionSlot::identifier) - 2);
|
||||
RNA_def_property_string_maxlength(prop, sizeof(ActionSlot::identifier));
|
||||
RNA_def_property_update(prop, NC_ANIMATION | ND_ANIMCHAN, "rna_ActionSlot_identifier_update");
|
||||
RNA_def_property_ui_text(
|
||||
prop,
|
||||
|
||||
@@ -9,7 +9,7 @@ import pathlib
|
||||
import bpy
|
||||
|
||||
"""
|
||||
blender -b --factory-startup --python tests/python/bl_animation_action.py
|
||||
blender -b --factory-startup --python tests/python/bl_animation_action.py -- --testdir tests/data/animation/
|
||||
"""
|
||||
|
||||
|
||||
@@ -67,6 +67,31 @@ class ActionSlotCreationTest(unittest.TestCase):
|
||||
# not supported in the Python API.
|
||||
self.action.slots.new('UNSPECIFIED', "Bob")
|
||||
|
||||
def test_long_identifier(self):
|
||||
# Test a 65-character identifier, using a 63-character name. This is the
|
||||
# maximum length allowed (the DNA field is MAX_ID_NAME=66 long, which
|
||||
# includes the trailing zero byte).
|
||||
long_but_ok_name = "This name is so long! It might look long, but it is just right!"
|
||||
slot_ok = self.action.slots.new('OBJECT', long_but_ok_name)
|
||||
self.assertEqual(long_but_ok_name, slot_ok.name_display, "this name should fit")
|
||||
self.assertEqual('OB' + long_but_ok_name, slot_ok.identifier, "this identifier should fit")
|
||||
|
||||
# Test one character more.
|
||||
too_long_name = "This name is so long! It might look long, and that it is indeed."
|
||||
too_long_name_truncated = too_long_name[:63]
|
||||
slot_long = self.action.slots.new('OBJECT', too_long_name)
|
||||
self.assertEqual(too_long_name_truncated, slot_long.name_display, "this name should be truncated")
|
||||
self.assertEqual('OB' + too_long_name_truncated, slot_long.identifier, "this identifier should be truncated")
|
||||
|
||||
# Test with different trailing character.
|
||||
other_long_name = "This name is so long! It might look long, and that it is indeed!"
|
||||
truncated_and_unique = other_long_name[:59] + ".001"
|
||||
slot_long2 = self.action.slots.new('OBJECT', too_long_name)
|
||||
self.assertEqual(truncated_and_unique, slot_long2.name_display,
|
||||
"this name should be truncated and made unique")
|
||||
self.assertEqual('OB' + truncated_and_unique, slot_long2.identifier,
|
||||
"this identifier should be truncated and made unique")
|
||||
|
||||
|
||||
class ActionSlotAssignmentTest(unittest.TestCase):
|
||||
"""Test assigning actions & check reference counts."""
|
||||
|
||||
Reference in New Issue
Block a user