[Bf-blender-cvs] [da1350acdcb] master: Fix T60815: drag & drop crash when search menu is opened immediately after.

Brecht Van Lommel noreply at git.blender.org
Wed Mar 20 19:50:45 CET 2019


Commit: da1350acdcb4c335b0082864a8ba16d216544a1e
Author: Brecht Van Lommel
Date:   Wed Mar 20 19:26:54 2019 +0100
Branches: master
https://developer.blender.org/rBda1350acdcb4c335b0082864a8ba16d216544a1e

Fix T60815: drag & drop crash when search menu is opened immediately after.

Patch by matc, some further refactoring by me.

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

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

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/interface/interface_layout.c
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/space_node/node_select.c

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

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 80f58a9548b..bd08ed88603 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -846,7 +846,7 @@ bool    UI_search_item_add(uiSearchItems *items, const char *name, void *poin, i
 /* bfunc gets search item *poin as arg2, or if NULL the old string */
 void    UI_but_func_search_set(
         uiBut *but, uiButSearchCreateFunc cfunc, uiButSearchFunc sfunc,
-        void *arg1, uiButHandleFunc bfunc, void *active);
+        void *arg, bool free_arg, uiButHandleFunc bfunc, void *active);
 /* height in pixels, it's using hardcoded values still */
 int     UI_searchbox_size_y(void);
 int     UI_searchbox_size_x(void);
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 16c87b7a7d7..c4a81b529a9 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -2949,7 +2949,7 @@ static void ui_but_free(const bContext *C, uiBut *but)
 		MEM_freeN(but->hold_argN);
 	}
 
-	if (!but->editstr && but->free_search_arg) {
+	if (but->free_search_arg) {
 		MEM_SAFE_FREE(but->search_arg);
 	}
 
@@ -4717,7 +4717,7 @@ uiBut *uiDefSearchBut(uiBlock *block, void *arg, int retval, int icon, int maxle
 void UI_but_func_search_set(
         uiBut *but,
         uiButSearchCreateFunc search_create_func,
-        uiButSearchFunc search_func, void *arg,
+        uiButSearchFunc search_func, void *arg, bool free_arg,
         uiButHandleFunc bfunc, void *active)
 {
 	/* needed since callers don't have access to internal functions
@@ -4726,9 +4726,14 @@ void UI_but_func_search_set(
 		search_create_func = ui_searchbox_create_generic;
 	}
 
+	if (but->free_search_arg) {
+		MEM_SAFE_FREE(but->search_arg);
+	}
+
 	but->search_create_func = search_create_func;
 	but->search_func = search_func;
 	but->search_arg = arg;
+	but->free_search_arg = free_arg;
 
 	if (bfunc) {
 #ifdef DEBUG
@@ -4817,7 +4822,7 @@ uiBut *uiDefSearchButO_ptr(
 	but = uiDefSearchBut(block, arg, retval, icon, maxlen, x, y, width, height, a1, a2, tip);
 	UI_but_func_search_set(
 	        but, ui_searchbox_create_generic, operator_enum_search_cb,
-	        but, operator_enum_call_cb, NULL);
+	        but, false, operator_enum_call_cb, NULL);
 
 	but->optype = ot;
 	but->opcontext = WM_OP_EXEC_DEFAULT;
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index f31e90370a3..33cc534662a 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -3138,9 +3138,6 @@ static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data)
 
 			ui_searchbox_free(C, data->searchbox);
 			data->searchbox = NULL;
-			if (but->free_search_arg) {
-				MEM_SAFE_FREE(but->search_arg);
-			}
 		}
 
 		but->editstr = NULL;
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index 95791dc8811..ebff54ee6ae 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -2115,8 +2115,7 @@ void ui_but_add_search(uiBut *but, PointerRNA *ptr, PropertyRNA *prop, PointerRN
 
 		UI_but_func_search_set(
 		        but, ui_searchbox_create_generic, ui_rna_collection_search_cb,
-		        coll_search, NULL, NULL);
-		but->free_search_arg = true;
+		        coll_search, true, NULL, NULL);
 	}
 	else if (but->type == UI_BTYPE_SEARCH_MENU) {
 		/* In case we fail to find proper searchprop,
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index fbd6b1b3ede..b4bfdbd340f 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -216,7 +216,7 @@ static uiBlock *template_common_search_menu(
 	}
 	UI_but_func_search_set(
 	        but, ui_searchbox_create_generic, search_func,
-	        search_arg, handle_func, active_item);
+	        search_arg, false, handle_func, active_item);
 
 
 	UI_block_bounds_set_normal(block, 0.3f * U.widget_unit);
@@ -4348,7 +4348,7 @@ void UI_but_func_operator_search(uiBut *but)
 {
 	UI_but_func_search_set(
 	        but, ui_searchbox_create_operator, operator_search_cb,
-	        NULL, operator_call_cb, NULL);
+	        NULL, false, operator_call_cb, NULL);
 }
 
 void uiTemplateOperatorSearch(uiLayout *layout)
diff --git a/source/blender/editors/space_node/node_select.c b/source/blender/editors/space_node/node_select.c
index fae5f7b3f20..aed5c590bb4 100644
--- a/source/blender/editors/space_node/node_select.c
+++ b/source/blender/editors/space_node/node_select.c
@@ -1081,7 +1081,7 @@ static uiBlock *node_find_menu(bContext *C, ARegion *ar, void *arg_op)
 	UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP);
 
 	but = uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 10, 9 * UI_UNIT_X, UI_UNIT_Y, 0, 0, "");
-	UI_but_func_search_set(but, NULL, node_find_cb, op->type, node_find_call_cb, NULL);
+	UI_but_func_search_set(but, NULL, node_find_cb, op->type, false, node_find_call_cb, NULL);
 
 	/* fake button, it holds space for search items */
 	uiDefBut(block, UI_BTYPE_LABEL, 0, "", 10, 10 - UI_searchbox_size_y(), UI_searchbox_size_x(), UI_searchbox_size_y(), NULL, 0, 0, 0, 0, NULL);



More information about the Bf-blender-cvs mailing list