Revision: 36313
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36313
Author:   campbellbarton
Date:     2011-04-24 14:45:49 +0000 (Sun, 24 Apr 2011)
Log Message:
-----------
fix crash [#27158] Appending crash with preview.

Modified Paths:
--------------
    trunk/blender/source/blender/blenloader/BLO_readfile.h
    trunk/blender/source/blender/blenloader/intern/readblenentry.c
    trunk/blender/source/blender/editors/space_file/filelist.c

Modified: trunk/blender/source/blender/blenloader/BLO_readfile.h
===================================================================
--- trunk/blender/source/blender/blenloader/BLO_readfile.h      2011-04-24 
10:51:45 UTC (rev 36312)
+++ trunk/blender/source/blender/blenloader/BLO_readfile.h      2011-04-24 
14:45:49 UTC (rev 36313)
@@ -148,7 +148,7 @@
  * 
  * @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_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 @@
  * 
  * @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

Modified: trunk/blender/source/blender/blenloader/intern/readblenentry.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readblenentry.c      
2011-04-24 10:51:45 UTC (rev 36312)
+++ trunk/blender/source/blender/blenloader/intern/readblenentry.c      
2011-04-24 14:45:49 UTC (rev 36313)
@@ -144,7 +144,7 @@
        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 @@
        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 @@
                                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 @@
                }
                
        }
-       
+
+       *tot_prev= tot;
        return previews;
 }
 

Modified: trunk/blender/source/blender/editors/space_file/filelist.c
===================================================================
--- trunk/blender/source/blender/editors/space_file/filelist.c  2011-04-24 
10:51:45 UTC (rev 36312)
+++ trunk/blender/source/blender/editors/space_file/filelist.c  2011-04-24 
14:45:49 UTC (rev 36313)
@@ -1007,7 +1007,7 @@
 {
        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 @@
        
        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 @@
                }
        }
        
-       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;
                        

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to