Fix #30413: dynamic paint crash with texture slots with no texture assigned.
[blender.git] / source / blender / render / intern / source / render_texture.c
index 49bacbaf693921a6e14f1ef43aa018be7a541d82..1e91738c77dd9432930f3b6c77a2fec2c0ed33cd 100644 (file)
@@ -3556,6 +3556,8 @@ Material *RE_init_sample_material(Material *orig_mat, Scene *scene)
                if(mat->mtex[tex_nr]) {
                        MTex *mtex = mat->mtex[tex_nr];
 
+                       if(!mtex->tex) continue;
+
                        /* only keep compatible texflags */
                        mtex->texflag = mtex->texflag & (MTEX_RGBTOINT | MTEX_STENCIL | MTEX_NEGATIVE | MTEX_ALPHAMIX);
 
@@ -3629,9 +3631,12 @@ void RE_free_sample_material(Material *mat)
                if(mat->septex & (1<<tex_nr)) continue;
                if(mat->mtex[tex_nr]) {
                        MTex *mtex= mat->mtex[tex_nr];
-                       free_texture(mtex->tex);
-                       MEM_freeN(mtex->tex);
-                       mtex->tex = NULL;
+       
+                       if(mtex->tex) {
+                               free_texture(mtex->tex);
+                               MEM_freeN(mtex->tex);
+                               mtex->tex = NULL;
+                       }
                }
        }