Bugfix #26761
authorTon Roosendaal <ton@blender.org>
Mon, 4 Apr 2011 13:47:34 +0000 (13:47 +0000)
committerTon Roosendaal <ton@blender.org>
Mon, 4 Apr 2011 13:47:34 +0000 (13:47 +0000)
Texture preview render now doesn't increment/decrement material->texture
user counts anymore. Blenders library.c code could use some overhaul
once to support data relinkage and copying around better. :)

source/blender/blenkernel/intern/material.c
source/blender/editors/render/render_preview.c

index 14848de..ce4c3a2 100644 (file)
@@ -245,12 +245,11 @@ Material *localize_material(Material *ma)
        man= copy_libblock(ma);
        BLI_remlink(&G.main->mat, man);
 
+       /* no increment for texture ID users, in previewrender.c it prevents decrement */
        for(a=0; a<MAX_MTEX; a++) {
                if(ma->mtex[a]) {
                        man->mtex[a]= MEM_mallocN(sizeof(MTex), "copymaterial");
                        memcpy(man->mtex[a], ma->mtex[a], sizeof(MTex));
-                       /* free_material decrements! */
-                       id_us_plus((ID *)man->mtex[a]->tex);
                }
        }
        
index 73d7fc2..239b078 100644 (file)
@@ -1117,11 +1117,20 @@ static void shader_preview_free(void *customdata)
        
        if(sp->matcopy) {
                struct IDProperty *properties;
+               int a;
+               
                /* node previews */
                shader_preview_updatejob(sp);
                
                /* get rid of copied material */
                BLI_remlink(&pr_main->mat, sp->matcopy);
+               
+               /* free_material decrements texture, prevent this. hack alert! */
+               for(a=0; a<MAX_MTEX; a++) {
+                       MTex *mtex= sp->matcopy->mtex[a];
+                       if(mtex && mtex->tex) mtex->tex= NULL;
+               }
+               
                free_material(sp->matcopy);
 
                properties= IDP_GetProperties((ID *)sp->matcopy, FALSE);