Fix #122150: UI: layout.template_search() crash without an active item

`template_search` was introduced in c20c203b82

Seems it assumed an active item is always there.
Without an active item, we are running into a crash trying to get the
textbut width.

So solution is to not draw that text button at all until an active item
is chosen.

This also goes in line with what `template_ID` is doing (it also skips
the text button without an active item).

Pull Request: https://projects.blender.org/blender/blender/pulls/122165
This commit is contained in:
Philipp Oeser 2024-05-27 14:04:32 +02:00
parent 246c57cbe2
commit 59f21ebce0

View file

@ -2084,6 +2084,11 @@ static void template_search_add_button_name(uiBlock *block,
PointerRNA *active_ptr,
const StructRNA *type)
{
/* Skip text button without an active item. */
if (active_ptr->data == nullptr) {
return;
}
PropertyRNA *name_prop = RNA_struct_name_property(type);
const int width = template_search_textbut_width(active_ptr, name_prop);
const int height = template_search_textbut_height();