[Bf-blender-cvs] [22ffd69a91c] blender-v3.0-release: Fix T89313: Attribute search crash with animation playback

Hans Goudey noreply at git.blender.org
Wed Nov 10 22:43:27 CET 2021


Commit: 22ffd69a91c9287e4f61e620ec2beaf9b1ff22c1
Author: Hans Goudey
Date:   Wed Nov 10 15:43:18 2021 -0600
Branches: blender-v3.0-release
https://developer.blender.org/rB22ffd69a91c9287e4f61e620ec2beaf9b1ff22c1

Fix T89313: Attribute search crash with animation playback

rBc473b2ce8bdbf8fa42 improved the situation somewhat, but
attribute search still crashes during animation playback, because
the UI search data references stale memory. The proper solution
is to allow the search to own data rather than just referencing it,
but I would prefer not to do that for 3.0. In the meantime, just
disable attribute search when animation is playing.

Differential Revision: https://developer.blender.org/D13179

===================================================================

M	source/blender/editors/space_node/node_geometry_attribute_search.cc
M	source/blender/modifiers/intern/MOD_nodes.cc

===================================================================

diff --git a/source/blender/editors/space_node/node_geometry_attribute_search.cc b/source/blender/editors/space_node/node_geometry_attribute_search.cc
index d0ccbb03107..063e6348123 100644
--- a/source/blender/editors/space_node/node_geometry_attribute_search.cc
+++ b/source/blender/editors/space_node/node_geometry_attribute_search.cc
@@ -33,6 +33,7 @@
 #include "RNA_access.h"
 #include "RNA_enum_types.h"
 
+#include "ED_screen.h"
 #include "ED_undo.h"
 
 #include "BLT_translation.h"
@@ -64,6 +65,10 @@ BLI_STATIC_ASSERT(std::is_trivially_destructible_v<AttributeSearchData>, "");
 static void attribute_search_update_fn(
     const bContext *C, void *arg, const char *str, uiSearchItems *items, const bool is_first)
 {
+  if (ED_screen_animation_playing(CTX_wm_manager(C))) {
+    return;
+  }
+
   AttributeSearchData *data = static_cast<AttributeSearchData *>(arg);
 
   SpaceNode *snode = CTX_wm_space_node(C);
@@ -79,6 +84,9 @@ static void attribute_search_update_fn(
 
 static void attribute_search_exec_fn(bContext *C, void *data_v, void *item_v)
 {
+  if (ED_screen_animation_playing(CTX_wm_manager(C))) {
+    return;
+  }
   if (item_v == nullptr) {
     return;
   }
diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc
index 7740fe891e3..3444be40a59 100644
--- a/source/blender/modifiers/intern/MOD_nodes.cc
+++ b/source/blender/modifiers/intern/MOD_nodes.cc
@@ -88,6 +88,7 @@
 #include "MOD_ui_common.h"
 
 #include "ED_object.h"
+#include "ED_screen.h"
 #include "ED_spreadsheet.h"
 #include "ED_undo.h"
 
@@ -1128,8 +1129,17 @@ struct AttributeSearchData {
 /* This class must not have a destructor, since it is used by buttons and freed with #MEM_freeN. */
 BLI_STATIC_ASSERT(std::is_trivially_destructible_v<AttributeSearchData>, "");
 
-static NodesModifierData *get_modifier_data(Main &bmain, const AttributeSearchData &data)
+static NodesModifierData *get_modifier_data(Main &bmain,
+                                            const wmWindowManager &wm,
+                                            const AttributeSearchData &data)
 {
+  if (ED_screen_animation_playing(&wm)) {
+    /* Work around an issue where the attribute search exec function has stale pointers when data
+     * is reallocated when evaluating the node tree, causing a crash. This would be solved by
+     * allowing the UI search data to own arbitrary memory rather than just referencing it. */
+    return nullptr;
+  }
+
   const Object *object = (Object *)BKE_libblock_find_session_uuid(
       &bmain, ID_OB, data.object_session_uid);
   if (object == nullptr) {
@@ -1147,7 +1157,7 @@ static void attribute_search_update_fn(
     const bContext *C, void *arg, const char *str, uiSearchItems *items, const bool is_first)
 {
   AttributeSearchData &data = *static_cast<AttributeSearchData *>(arg);
-  const NodesModifierData *nmd = get_modifier_data(*CTX_data_main(C), data);
+  const NodesModifierData *nmd = get_modifier_data(*CTX_data_main(C), *CTX_wm_manager(C), data);
   if (nmd == nullptr) {
     return;
   }
@@ -1181,7 +1191,7 @@ static void attribute_search_exec_fn(bContext *C, void *data_v, void *item_v)
   }
   AttributeSearchData &data = *static_cast<AttributeSearchData *>(data_v);
   const GeometryAttributeInfo &item = *static_cast<const GeometryAttributeInfo *>(item_v);
-  const NodesModifierData *nmd = get_modifier_data(*CTX_data_main(C), data);
+  const NodesModifierData *nmd = get_modifier_data(*CTX_data_main(C), *CTX_wm_manager(C), data);
   if (nmd == nullptr) {
     return;
   }



More information about the Bf-blender-cvs mailing list