From dc9249c97f033d492d13535b9d4f20bc084b0186 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Mon, 11 Mar 2024 19:26:58 +0100 Subject: [PATCH] Fix #110562: Crash animating node property affecting socket visibility For various reasons, the animation system can't properly update the node tree so that the socket availability caused by changing node enum properties propagates completely. So animating node properties that affect socket visibility to change isn't possible without issues like crashes. Unfortunately that wasn't disallowed before. In this commit there is a balance of disabling animation on sockets that could reasonably expected to affect socket visibility, and minimizing breaking changes. Pull Request: https://projects.blender.org/blender/blender/pulls/119221 --- source/blender/makesrna/intern/rna_nodetree.cc | 9 +++++++++ source/blender/nodes/NOD_rna_define.hh | 3 ++- .../function/nodes/node_fn_align_euler_to_vector.cc | 10 ++++++++-- .../nodes/geometry/nodes/node_geo_accumulate_field.cc | 3 ++- .../geometry/nodes/node_geo_attribute_capture.cc | 3 ++- .../geometry/nodes/node_geo_attribute_statistic.cc | 3 ++- .../geometry/nodes/node_geo_curve_spline_type.cc | 4 +++- .../geometry/nodes/node_geo_duplicate_elements.cc | 4 +++- .../geometry/nodes/node_geo_mesh_primitive_circle.cc | 4 +++- .../geometry/nodes/node_geo_mesh_primitive_cone.cc | 4 +++- .../nodes/node_geo_mesh_primitive_cylinder.cc | 4 +++- .../nodes/geometry/nodes/node_geo_mesh_to_points.cc | 4 +++- .../geometry/nodes/node_geo_subdivision_surface.cc | 8 ++++++-- .../nodes/geometry/nodes/node_geo_triangulate.cc | 8 ++++++-- source/blender/nodes/intern/node_rna_define.cc | 11 +++++++++-- 15 files changed, 64 insertions(+), 18 deletions(-) diff --git a/source/blender/makesrna/intern/rna_nodetree.cc b/source/blender/makesrna/intern/rna_nodetree.cc index 2c187a9bcb0..9830176d338 100644 --- a/source/blender/makesrna/intern/rna_nodetree.cc +++ b/source/blender/makesrna/intern/rna_nodetree.cc @@ -8919,6 +8919,7 @@ static void def_geo_curve_sample(StructRNA *srna) prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE); RNA_def_property_enum_items(prop, mode_items); RNA_def_property_ui_text(prop, "Mode", "Method for sampling input"); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update"); prop = RNA_def_property(srna, "use_all_curves", PROP_BOOLEAN, PROP_NONE); @@ -8926,6 +8927,7 @@ static void def_geo_curve_sample(StructRNA *srna) "All Curves", "Sample lengths based on the total length of all curves, rather than " "using a length inside each selected curve"); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update"); prop = RNA_def_property(srna, "data_type", PROP_ENUM, PROP_NONE); @@ -8934,6 +8936,7 @@ static void def_geo_curve_sample(StructRNA *srna) prop, nullptr, nullptr, "rna_GeometryNodeAttributeType_type_with_socket_itemf"); RNA_def_property_enum_default(prop, CD_PROP_FLOAT); RNA_def_property_ui_text(prop, "Data Type", ""); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update"); } @@ -8976,6 +8979,7 @@ static void def_geo_distribute_points_on_faces(StructRNA *srna) RNA_def_property_enum_items(prop, rna_node_geometry_distribute_points_on_faces_mode_items); RNA_def_property_enum_default(prop, GEO_NODE_POINT_DISTRIBUTE_POINTS_ON_FACES_RANDOM); RNA_def_property_ui_text(prop, "Distribution Method", "Method to use for scattering points"); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update"); prop = RNA_def_property(srna, "use_legacy_normal", PROP_BOOLEAN, PROP_NONE); @@ -8984,6 +8988,7 @@ static void def_geo_distribute_points_on_faces(StructRNA *srna) "Legacy Normal", "Output the normal and rotation values that have been output " "before the node started taking smooth normals into account"); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update"); } @@ -8997,12 +9002,14 @@ static void def_geo_curve_set_handle_type(StructRNA *srna) RNA_def_property_enum_sdna(prop, nullptr, "handle_type"); RNA_def_property_ui_text(prop, "Handle Type", ""); RNA_def_property_enum_items(prop, rna_node_geometry_curve_handle_type_items); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update"); prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE); RNA_def_property_enum_items(prop, rna_enum_node_geometry_curve_handle_side_items); RNA_def_property_ui_text(prop, "Mode", "Whether to update left and right handles"); RNA_def_property_flag(prop, PROP_ENUM_FLAG); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update"); } @@ -9345,6 +9352,7 @@ static void rna_def_geo_bake(StructRNA *srna) nullptr, nullptr); RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NO_DEG_UPDATE); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_ui_text(prop, "Active Item Index", "Index of the active item"); RNA_def_property_update(prop, NC_NODE, nullptr); } @@ -9474,6 +9482,7 @@ static void def_geo_sample_index(StructRNA *srna) prop, nullptr, nullptr, "rna_GeometryNodeAttributeType_type_with_socket_itemf"); RNA_def_property_enum_default(prop, CD_PROP_FLOAT); RNA_def_property_ui_text(prop, "Data Type", ""); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update"); prop = RNA_def_property(srna, "domain", PROP_ENUM, PROP_NONE); diff --git a/source/blender/nodes/NOD_rna_define.hh b/source/blender/nodes/NOD_rna_define.hh index 3b536346790..37c1465906d 100644 --- a/source/blender/nodes/NOD_rna_define.hh +++ b/source/blender/nodes/NOD_rna_define.hh @@ -68,6 +68,7 @@ PropertyRNA *RNA_def_node_enum(StructRNA *srna, const EnumPropertyItem *static_items, const EnumRNAAccessors accessors, std::optional default_value = std::nullopt, - const EnumPropertyItemFunc item_func = nullptr); + const EnumPropertyItemFunc item_func = nullptr, + bool allow_animation = false); } // namespace blender::nodes diff --git a/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc b/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc index 339181bb4e4..2058a5f2a87 100644 --- a/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc +++ b/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc @@ -241,14 +241,20 @@ static void node_rna(StructRNA *srna) "Axis", "Axis to align to the vector", axis_items, - NOD_inline_enum_accessors(custom1)); + NOD_inline_enum_accessors(custom1), + std::nullopt, + nullptr, + true); RNA_def_node_enum(srna, "pivot_axis", "Pivot Axis", "Axis to rotate around", pivot_axis_items, - NOD_inline_enum_accessors(custom2)); + NOD_inline_enum_accessors(custom2), + std::nullopt, + nullptr, + true); } static void node_register() diff --git a/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc b/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc index 0f332c29216..5d18e2c999c 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc @@ -389,7 +389,8 @@ static void node_rna(StructRNA *srna) rna_enum_attribute_domain_items, NOD_storage_enum_accessors(domain), int(AttrDomain::Point), - enums::domain_experimental_grease_pencil_version3_fn); + enums::domain_experimental_grease_pencil_version3_fn, + true); } static void node_register() diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc index 1b5a8b4d453..350b0cab782 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc @@ -184,7 +184,8 @@ static void node_rna(StructRNA *srna) rna_enum_attribute_domain_items, NOD_storage_enum_accessors(domain), int8_t(AttrDomain::Point), - enums::domain_experimental_grease_pencil_version3_fn); + enums::domain_experimental_grease_pencil_version3_fn, + true); } static void node_register() diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_statistic.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_statistic.cc index b0010e2955a..a17ad8a743b 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_attribute_statistic.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_statistic.cc @@ -356,7 +356,8 @@ static void node_rna(StructRNA *srna) rna_enum_attribute_domain_items, NOD_inline_enum_accessors(custom2), int(AttrDomain::Point), - enums::domain_experimental_grease_pencil_version3_fn); + enums::domain_experimental_grease_pencil_version3_fn, + true); } static void node_register() diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_spline_type.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_spline_type.cc index e1238035733..b6414de0b02 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_spline_type.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_spline_type.cc @@ -93,7 +93,9 @@ static void node_rna(StructRNA *srna) "The curve type to change the selected curves to", rna_enum_curves_type_items, NOD_storage_enum_accessors(spline_type), - CURVE_TYPE_POLY); + CURVE_TYPE_POLY, + nullptr, + true); } static void node_register() diff --git a/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc b/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc index 319a2553da9..bfc7019a561 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc @@ -1063,7 +1063,9 @@ static void node_rna(StructRNA *srna) "Which domain to duplicate", domain_items, NOD_storage_enum_accessors(domain), - int(AttrDomain::Point)); + int(AttrDomain::Point), + nullptr, + true); } static void node_register() diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_circle.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_circle.cc index 284f93a0d58..87e16c5f7fe 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_circle.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_circle.cc @@ -212,7 +212,9 @@ static void node_rna(StructRNA *srna) "", rna_enum_node_geometry_mesh_circle_fill_type_items, NOD_storage_enum_accessors(fill_type), - GEO_NODE_MESH_CIRCLE_FILL_NONE); + GEO_NODE_MESH_CIRCLE_FILL_NONE, + nullptr, + true); } static void node_register() diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc index 7e264fb0f2d..7676f7e2977 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc @@ -148,7 +148,9 @@ static void node_rna(StructRNA *srna) "", rna_enum_node_geometry_mesh_circle_fill_type_items, NOD_storage_enum_accessors(fill_type), - GEO_NODE_MESH_CIRCLE_FILL_NGON); + GEO_NODE_MESH_CIRCLE_FILL_NGON, + nullptr, + true); } static void node_register() diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cylinder.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cylinder.cc index 766eb0f1af4..e78023b0bc6 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cylinder.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cylinder.cc @@ -139,7 +139,9 @@ static void node_rna(StructRNA *srna) "", rna_enum_node_geometry_mesh_circle_fill_type_items, NOD_storage_enum_accessors(fill_type), - GEO_NODE_MESH_CIRCLE_FILL_NGON); + GEO_NODE_MESH_CIRCLE_FILL_NGON, + nullptr, + true); } static void node_register() diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_to_points.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_to_points.cc index b1213cf536a..92d87eb87c2 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_to_points.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_to_points.cc @@ -234,7 +234,9 @@ static void node_rna(StructRNA *srna) "", mode_items, NOD_storage_enum_accessors(mode), - GEO_NODE_MESH_TO_POINTS_VERTICES); + GEO_NODE_MESH_TO_POINTS_VERTICES, + nullptr, + true); } static void node_register() diff --git a/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc b/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc index ca492517717..efbfb456cc5 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc @@ -206,7 +206,9 @@ static void node_rna(StructRNA *srna) "Controls how smoothing is applied to UVs", rna_enum_subdivision_uv_smooth_items, NOD_storage_enum_accessors(uv_smooth), - SUBSURF_UV_SMOOTH_PRESERVE_BOUNDARIES); + SUBSURF_UV_SMOOTH_PRESERVE_BOUNDARIES, + nullptr, + true); RNA_def_node_enum(srna, "boundary_smooth", @@ -214,7 +216,9 @@ static void node_rna(StructRNA *srna) "Controls how open boundaries are smoothed", rna_enum_subdivision_boundary_smooth_items, NOD_storage_enum_accessors(boundary_smooth), - SUBSURF_BOUNDARY_SMOOTH_ALL); + SUBSURF_BOUNDARY_SMOOTH_ALL, + nullptr, + true); } static void node_register() diff --git a/source/blender/nodes/geometry/nodes/node_geo_triangulate.cc b/source/blender/nodes/geometry/nodes/node_geo_triangulate.cc index e67469b41a0..ab5dc4e0a23 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_triangulate.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_triangulate.cc @@ -156,7 +156,9 @@ static void node_rna(StructRNA *srna) "Method for splitting the quads into triangles", rna_node_geometry_triangulate_quad_method_items, NOD_inline_enum_accessors(custom1), - GEO_NODE_POINTS_TO_VOLUME_RESOLUTION_MODE_AMOUNT); + GEO_NODE_POINTS_TO_VOLUME_RESOLUTION_MODE_AMOUNT, + nullptr, + true); RNA_def_node_enum(srna, "ngon_method", @@ -164,7 +166,9 @@ static void node_rna(StructRNA *srna) "Method for splitting the n-gons into triangles", rna_node_geometry_triangulate_ngon_method_items, NOD_inline_enum_accessors(custom2), - GEO_NODE_POINTS_TO_VOLUME_RESOLUTION_MODE_AMOUNT); + GEO_NODE_POINTS_TO_VOLUME_RESOLUTION_MODE_AMOUNT, + nullptr, + true); } static void node_register() diff --git a/source/blender/nodes/intern/node_rna_define.cc b/source/blender/nodes/intern/node_rna_define.cc index dd990f2934e..3d01a16f922 100644 --- a/source/blender/nodes/intern/node_rna_define.cc +++ b/source/blender/nodes/intern/node_rna_define.cc @@ -29,7 +29,8 @@ PropertyRNA *RNA_def_node_enum(StructRNA *srna, const EnumPropertyItem *static_items, const EnumRNAAccessors accessors, std::optional default_value, - const EnumPropertyItemFunc item_func) + const EnumPropertyItemFunc item_func, + const bool allow_animation) { PropertyRNA *prop = RNA_def_property(srna, identifier, PROP_ENUM, PROP_NONE); RNA_def_property_enum_funcs_runtime(prop, accessors.getter, accessors.setter, item_func); @@ -38,7 +39,13 @@ PropertyRNA *RNA_def_node_enum(StructRNA *srna, RNA_def_property_enum_default(prop, *default_value); } RNA_def_property_ui_text(prop, ui_name, ui_description); - RNA_def_property_update_runtime(prop, rna_Node_socket_update); + if (allow_animation) { + RNA_def_property_update_runtime(prop, rna_Node_update); + } + else { + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_update_runtime(prop, rna_Node_socket_update); + } RNA_def_property_update_notifier(prop, NC_NODE | NA_EDITED); return prop; }