From 37fab4a3e1b08c0fda42e73763f63c3443eb45fc Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 26 May 2010 10:52:39 +0000 Subject: [PATCH] bugfix [#22426] New Thumbnail code crashes when saving patch from Ken Nign (ken9). (modified slightly) --- source/blender/windowmanager/intern/wm_files.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 91ebb5d6fb4..a6e59cde402 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -502,9 +502,7 @@ static void writeThumb(const char *path, Scene *scene, int **thumb_pt) if(G.background || scene->camera==NULL) return; - - thumb = MEM_mallocN(((2 + (BLEN_THUMB_SIZE * BLEN_THUMB_SIZE))) * sizeof(int), "write_file thumb"); - + /* gets scaled to BLEN_THUMB_SIZE */ ibuf= ED_view3d_draw_offscreen_imbuf_simple(scene, BLEN_THUMB_SIZE * 2, BLEN_THUMB_SIZE * 2, OB_SOLID); @@ -514,16 +512,24 @@ static void writeThumb(const char *path, Scene *scene, int **thumb_pt) IMB_scaleImBuf(ibuf, BLEN_THUMB_SIZE, BLEN_THUMB_SIZE); /* first write into thumb buffer */ + thumb= MEM_mallocN(((2 + (BLEN_THUMB_SIZE * BLEN_THUMB_SIZE))) * sizeof(int), "write_file thumb"); + thumb[0] = BLEN_THUMB_SIZE; thumb[1] = BLEN_THUMB_SIZE; + memcpy(thumb + 2, ibuf->rect, BLEN_THUMB_SIZE * BLEN_THUMB_SIZE * sizeof(int)); /* the image is scaled here */ ibuf= IMB_thumb_create(path, THB_NORMAL, THB_SOURCE_BLEND, ibuf); - } - if (ibuf) { - IMB_freeImBuf(ibuf); + if (ibuf) + IMB_freeImBuf(ibuf); + + ibuf= NULL; + } + else { + /* '*thumb_pt' needs to stay NULL to prevent a bad thumbnail from being handled */ + thumb= NULL; } /* must be freed by caller */