From ef2151d73de87b3e7be631b6712283a727f8d4a6 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Tue, 15 Dec 2020 12:02:22 +0100 Subject: Fix T83776: Crashes with add-on's icon preview in menus Apparently the ID pointer can be NULL, which most code here assumes is not the case. But it's very fragile & finicky, there is one code path were it's allowed to be NULL. Add necessary NULL-checks, an assert as sanity check and a comment to note the possibility of NULL. --- source/blender/editors/render/render_preview.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c index 4466d9f434d..3c103f28d93 100644 --- a/source/blender/editors/render/render_preview.c +++ b/source/blender/editors/render/render_preview.c @@ -189,7 +189,7 @@ typedef struct IconPreview { Main *bmain; Scene *scene; void *owner; - ID *id, *id_copy; + ID *id, *id_copy; /* May be NULL! (see ICON_TYPE_PREVIEW case in #ui_icon_ensure_deferred()) */ ListBase sizes; } IconPreview; @@ -1235,6 +1235,8 @@ static void icon_preview_startjob(void *customdata, short *stop, short *do_updat ID *id = sp->id; short idtype = GS(id->name); + BLI_assert(id != NULL); + if (idtype == ID_IM) { Image *ima = (Image *)id; ImBuf *ibuf = NULL; @@ -1337,7 +1339,7 @@ static void other_id_types_preview_render(IconPreview *ip, const bool is_render = !is_deferred; /* These types don't use the ShaderPreview mess, they have their own types and functions. */ - BLI_assert(!ELEM(GS(ip->id->name), ID_OB)); + BLI_assert(!ip->id || !ELEM(GS(ip->id->name), ID_OB)); /* construct shader preview from image size and previewcustomdata */ sp->scene = ip->scene; @@ -1396,7 +1398,7 @@ static void icon_preview_startjob_all_sizes(void *customdata, continue; } - if (ELEM(GS(ip->id->name), ID_OB)) { + if (ip->id && ELEM(GS(ip->id->name), ID_OB)) { /* Much simpler than the ShaderPreview mess used for other ID types. */ object_preview_render(ip, cur_size); } -- cgit v1.2.3