Fix #117988: Anim, Crash when baking action

When baking custom properties, avoid keeping references to custom
property values that are known to be impossible to animate anyway.

The crash was caused by custom properties containing collections of ID
properties. Keeping Python references around for too long and then
accessing them caused Blender to crash.

My solution is to only keep track of custom property values that might
be keyable. For some this is certain: floats, ints, bools are keyable,
whereas lists, dicts, etc. are not. However, strings can be the RNA
value for an enum property, which is keyed via its integer
representation. So, the new function `can_be_keyed()` can return `True`,
`False`, or `None`. By skipping those values where it returns `False`
the crash is already resolved, making it good enough for now.

Pull Request: https://projects.blender.org/blender/blender/pulls/117993
This commit is contained in:
Sybren A. Stüvel 2024-02-08 15:40:55 +01:00
parent bf94b454c4
commit 25bdaf026c
1 changed files with 29 additions and 0 deletions

View File

@ -205,11 +205,40 @@ def bake_action_iter(
"bbone_easeout": 1,
}
def can_be_keyed(value):
"""Returns a tri-state boolean.
- True: known to be keyable.
- False: known to not be keyable.
- None: unknown, might be an enum property for which RNA uses a string to
indicate a specific item (keyable) or an actual string property (not
keyable).
"""
if isinstance(value, (int, float, bool)):
# These types are certainly keyable.
return True
if isinstance(value, (list, tuple, set, dict)):
# These types are certainly not keyable.
return False
# Maybe this could be made stricter, as also ID pointer properties and
# some other types cannot be keyed. However, the above checks are enough
# to fix the crash that this code was written for (#117988).
return None
# Convert rna_prop types (IDPropertyArray, etc) to python types.
def clean_custom_properties(obj):
if not bake_options.do_custom_props:
# Don't bother remembering any custom properties when they're not
# going to be baked anyway.
return {}
# Be careful about which properties to actually consider for baking, as
# keeping references to complex Blender datastructures around for too long
# can cause crashes. See #117988.
clean_props = {
key: rna_idprop_value_to_python(value)
for key, value in obj.items()
if can_be_keyed(value) is not False
}
return clean_props