Fix crash when using template_search with non-ID data

This commit is contained in:
Julian Eisel
2017-05-13 19:48:04 +02:00
parent 2d22092230
commit 77a90f7666

View File

@@ -214,11 +214,12 @@ int uiDefAutoButsRNA(
return tot;
}
/* *** RNA collection search menu *** */
typedef struct CollItemSearch {
struct CollItemSearch *next, *prev;
ID *id;
void *data;
char *name;
int index;
int iconid;
@@ -247,7 +248,6 @@ void ui_rna_collection_search_cb(const struct bContext *C, void *arg, const char
/* build a temporary list of relevant items first */
RNA_PROP_BEGIN (&data->search_ptr, itemptr, data->search_prop)
{
ID *id = NULL;
if (flag & PROP_ID_SELF_CHECK)
if (itemptr.data == data->target_ptr.id.data)
@@ -262,14 +262,13 @@ void ui_rna_collection_search_cb(const struct bContext *C, void *arg, const char
name = RNA_struct_name_get_alloc(&itemptr, NULL, 0, NULL); /* could use the string length here */
iconid = 0;
if (itemptr.type && RNA_struct_is_ID(itemptr.type)) {
id = itemptr.data;
iconid = ui_id_icon_get(C, id, false);
iconid = ui_id_icon_get(C, itemptr.data, false);
}
if (name) {
if (skip_filter || BLI_strcasestr(name, str)) {
cis = MEM_callocN(sizeof(CollItemSearch), "CollectionItemSearch");
cis->id = id;
cis->data = itemptr.data;
cis->name = MEM_dupallocN(name);
cis->index = i;
cis->iconid = iconid;
@@ -286,8 +285,7 @@ void ui_rna_collection_search_cb(const struct bContext *C, void *arg, const char
/* add search items from temporary list */
for (cis = items_list->first; cis; cis = cis->next) {
void *poin = cis->id ? cis->id : SET_INT_IN_POINTER(cis->index);
if (UI_search_item_add(items, cis->name, poin, cis->iconid) == false) {
if (UI_search_item_add(items, cis->name, cis->data, cis->iconid) == false) {
break;
}
}