fix crash [#27158] Appending crash with preview.
authorCampbell Barton <ideasman42@gmail.com>
Sun, 24 Apr 2011 14:45:49 +0000 (14:45 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 24 Apr 2011 14:45:49 +0000 (14:45 +0000)
source/blender/blenloader/BLO_readfile.h
source/blender/blenloader/intern/readblenentry.c
source/blender/editors/space_file/filelist.c

index 891dc47b4aedfc3cbd1a43a96242f68247e2730a..22083eda1c8d94f0c1e083fdbcf8d6a13d1aeb21 100644 (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
index ae4ba6629a66fd5c4151dd2c8285e29062acc825..abc469a5355dcea2f4aca84be96249a747844b53 100644 (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;
 }
 
index f0ffe34476f46e6843dc56738ed4ea0ab3c00fa2..f815c7b4ac5c091956981c57a1e58695f7f9d600 100644 (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;