From fd45310dfe30952081ef51f80e62543664ca84a5 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 24 Apr 2011 14:45:49 +0000 Subject: fix crash [#27158] Appending crash with preview. --- source/blender/blenloader/BLO_readfile.h | 8 +++++--- source/blender/blenloader/intern/readblenentry.c | 7 +++++-- source/blender/editors/space_file/filelist.c | 16 ++++++++++------ 3 files changed, 20 insertions(+), 11 deletions(-) (limited to 'source') diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h index 891dc47b4ae..22083eda1c8 100644 --- a/source/blender/blenloader/BLO_readfile.h +++ b/source/blender/blenloader/BLO_readfile.h @@ -148,7 +148,7 @@ BLO_blendhandle_from_memory( * * @param bh The blendhandle to access. * @param ofblocktype The type of names to get. - * @param totnames The length of the returned list. + * @param tot_names The length of the returned list. * @return A BLI_linklist of strings. The string links * should be freed with malloc. */ @@ -156,7 +156,7 @@ BLO_blendhandle_from_memory( BLO_blendhandle_get_datablock_names( BlendHandle *bh, int ofblocktype, - int *totnames); + int *tot_names); /** * Gets the previews of all the datablocks in a file @@ -165,13 +165,15 @@ BLO_blendhandle_get_datablock_names( * * @param bh The blendhandle to access. * @param ofblocktype The type of names to get. + * @param tot_prev The length of the returned list. * @return A BLI_linklist of PreviewImage. The PreviewImage links * should be freed with malloc. */ struct LinkNode* BLO_blendhandle_get_previews( BlendHandle *bh, - int ofblocktype); + int ofblocktype, + int *tot_prev); /** * Gets the names of all the datablock groups in a diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c index ae4ba6629a6..abc469a5355 100644 --- a/source/blender/blenloader/intern/readblenentry.c +++ b/source/blender/blenloader/intern/readblenentry.c @@ -144,7 +144,7 @@ LinkNode *BLO_blendhandle_get_datablock_names(BlendHandle *bh, int ofblocktype, return names; } -LinkNode *BLO_blendhandle_get_previews(BlendHandle *bh, int ofblocktype) +LinkNode *BLO_blendhandle_get_previews(BlendHandle *bh, int ofblocktype, int *tot_prev) { FileData *fd= (FileData*) bh; LinkNode *previews= NULL; @@ -153,6 +153,7 @@ LinkNode *BLO_blendhandle_get_previews(BlendHandle *bh, int ofblocktype) int npreviews = 0; PreviewImage* prv = NULL; PreviewImage* new_prv = NULL; + int tot= 0; for (bhead= blo_firstbhead(fd); bhead; bhead= blo_nextbhead(fd, bhead)) { if (bhead->code==ofblocktype) { @@ -166,6 +167,7 @@ LinkNode *BLO_blendhandle_get_previews(BlendHandle *bh, int ofblocktype) case ID_LA: /* fall through */ new_prv = MEM_callocN(sizeof(PreviewImage), "newpreview"); BLI_linklist_prepend(&previews, new_prv); + tot++; looking = 1; break; default: @@ -213,7 +215,8 @@ LinkNode *BLO_blendhandle_get_previews(BlendHandle *bh, int ofblocktype) } } - + + *tot_prev= tot; return previews; } diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index f0ffe34476f..f815c7b4ac5 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -1007,7 +1007,7 @@ void filelist_from_library(struct FileList* filelist) { LinkNode *l, *names, *previews; struct ImBuf* ima; - int ok, i, nnames, idcode; + int ok, i, nprevs, nnames, idcode; char filename[FILE_MAXDIR+FILE_MAXFILE]; char dir[FILE_MAX], group[GROUP_MAX]; @@ -1031,17 +1031,18 @@ void filelist_from_library(struct FileList* filelist) idcode= groupname_to_code(group); - // memory for strings is passed into filelist[i].relname - // and free'd in freefilelist - previews = NULL; + /* memory for strings is passed into filelist[i].relname + * and free'd in freefilelist */ if (idcode) { - previews= BLO_blendhandle_get_previews(filelist->libfiledata, idcode); + previews= BLO_blendhandle_get_previews(filelist->libfiledata, idcode, &nprevs); names= BLO_blendhandle_get_datablock_names(filelist->libfiledata, idcode, &nnames); /* ugh, no rewind, need to reopen */ BLO_blendhandle_close(filelist->libfiledata); filelist->libfiledata= BLO_blendhandle_from_file(dir, NULL); } else { + previews= NULL; + nprevs= 0; names= BLO_blendhandle_get_linkable_groups(filelist->libfiledata); nnames= BLI_linklist_length(names); } @@ -1064,7 +1065,10 @@ void filelist_from_library(struct FileList* filelist) } } - if(previews) { + if(previews && (nnames != nprevs)) { + printf("filelist_from_library: error, found %d items, %d previews\n", nnames, nprevs); + } + else if(previews) { for (i=0, l= previews; inext) { PreviewImage *img= l->link; -- cgit v1.2.3