fix crash [#27158] Appending crash with preview.

This commit is contained in:
Campbell Barton
2011-04-24 14:45:49 +00:00
parent 8fdebf24f4
commit fd45310dfe
3 changed files with 20 additions and 11 deletions

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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; i<nnames; i++, l= l->next) {
PreviewImage *img= l->link;