Tool System: display tooltip generation error

While this shouldn't ever happen there have been reports
of tooltip creation failure - keep this until the issue is resolved.
This commit is contained in:
Campbell Barton 2018-11-07 14:40:44 +11:00
parent 4e11b6f037
commit 0bd61227c2
Notes: blender-bot 2023-02-14 06:37:09 +01:00
Referenced by issue #57639, Crash related to ui_tooltip
1 changed files with 21 additions and 11 deletions

View File

@ -420,22 +420,32 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is
tool_name);
char *expr_result = NULL;
bool is_error = false;
if (BPY_execute_string_as_string(C, expr_imports, expr, true, &expr_result)) {
if (!STREQ(expr_result, ".")) {
uiTooltipField *field = text_field_add(
data, &(uiTooltipFormat){
.style = UI_TIP_STYLE_NORMAL,
.color_id = UI_TIP_LC_MAIN,
.is_pad = true,
});
field->text = expr_result;
}
else {
if (STREQ(expr_result, ".")) {
MEM_freeN(expr_result);
expr_result = NULL;
}
}
else {
BLI_assert(0);
/* Note, this is an exceptional case, we could even remove it
* however there have been reports of tooltips failing, so keep it for now. */
expr_result = BLI_strdup("Internal error!");
is_error = true;
}
if (expr_result != NULL) {
uiTooltipField *field = text_field_add(
data, &(uiTooltipFormat){
.style = UI_TIP_STYLE_NORMAL,
.color_id = UI_TIP_LC_MAIN,
.is_pad = true,
});
field->text = expr_result;
if (UNLIKELY(is_error)) {
field->format.color_id = UI_TIP_LC_ALERT;
}
}
}