Commit: 47afa53913f8b9ece3b57e8cdf4b5bb8aa77aa43
Author: Lukas Tönne
Date:   Wed Mar 4 18:01:32 2015 +0100
Branches: alembic_pointcache
https://developer.blender.org/rB47afa53913f8b9ece3b57e8cdf4b5bb8aa77aa43

Use a dedicated input_dm pointer in the cache modifier to provide a mesh
result read from the cache.

Mixing this with the output_dm used for writing leads to undefined
situations where the DM was released but should actually be passed on.

===================================================================

M       source/blender/blenkernel/intern/DerivedMesh.c
M       source/blender/blenloader/intern/readfile.c
M       source/blender/makesdna/DNA_modifier_types.h
M       source/blender/modifiers/intern/MOD_cache.c

===================================================================

diff --git a/source/blender/blenkernel/intern/DerivedMesh.c 
b/source/blender/blenkernel/intern/DerivedMesh.c
index 902f448..affc104 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -1572,7 +1572,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, 
float (*inputVertexCos
                        /* use the cache result as output of the modifier
                         * rather than as the final dm
                         */
-                       cmd->output_dm = cachedm;
+                       cmd->input_dm = cachedm;
                        cachedm = NULL;
                }
                else
@@ -1915,8 +1915,8 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, 
float (*inputVertexCos
         * - If we have no DerivedMesh then we need to build one.
         */
        if (cachedm) {
-               finaldm = CDDM_copy(cachedm);
-               cachedm->release(cachedm);
+               finaldm = cachedm;
+               cachedm = NULL;
        }
        else if (dm && deformedVerts) {
                finaldm = CDDM_copy(dm);
diff --git a/source/blender/blenloader/intern/readfile.c 
b/source/blender/blenloader/intern/readfile.c
index d4bfb2b..684d1e9 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4938,6 +4938,7 @@ static void direct_link_modifiers(FileData *fd, ListBase 
*lb)
                        CacheModifierData *cmd = (CacheModifierData *)md;
                        
                        cmd->output_dm = NULL;
+                       cmd->input_dm = NULL;
                        cmd->flag &= ~(MOD_CACHE_USE_OUTPUT_REALTIME | 
MOD_CACHE_USE_OUTPUT_RENDER);
                }
        }
diff --git a/source/blender/makesdna/DNA_modifier_types.h 
b/source/blender/makesdna/DNA_modifier_types.h
index c5b1029..368c4fd 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1450,7 +1450,11 @@ typedef struct CacheModifierData {
        int flag;
        int pad;
        
+       /* DM data for writing into the cache */
        struct DerivedMesh *output_dm;
+       
+       /* DM data read from the cache for modifier input */
+       struct DerivedMesh *input_dm;
 } CacheModifierData;
 
 typedef enum eCacheModifier_Flag {
diff --git a/source/blender/modifiers/intern/MOD_cache.c 
b/source/blender/modifiers/intern/MOD_cache.c
index d65b769..70b434c 100644
--- a/source/blender/modifiers/intern/MOD_cache.c
+++ b/source/blender/modifiers/intern/MOD_cache.c
@@ -63,6 +63,7 @@ static void copyData(ModifierData *md, ModifierData *target)
        modifier_copyData_generic(md, target);
        
        tpcmd->output_dm = NULL;
+       tpcmd->input_dm = NULL;
        tpcmd->flag &= ~(MOD_CACHE_USE_OUTPUT_REALTIME | 
MOD_CACHE_USE_OUTPUT_RENDER);
 }
 
@@ -74,6 +75,10 @@ static void freeData(ModifierData *md)
                pcmd->output_dm->release(pcmd->output_dm);
                pcmd->output_dm = NULL;
        }
+       if (pcmd->input_dm) {
+               pcmd->input_dm->release(pcmd->input_dm);
+               pcmd->input_dm = NULL;
+       }
 }
 
 static DerivedMesh *pointcache_do(CacheModifierData *pcmd, Object *UNUSED(ob), 
DerivedMesh *dm, ModifierApplyFlag flag)
@@ -87,12 +92,19 @@ static DerivedMesh *pointcache_do(CacheModifierData *pcmd, 
Object *UNUSED(ob), D
                pcmd->output_dm = CDDM_copy(dm);
        }
        else {
+               /* unused cache output? clean up! */
                if (pcmd->output_dm) {
-                       dm = pcmd->output_dm;
+                       pcmd->output_dm->release(pcmd->output_dm);
                        pcmd->output_dm = NULL;
                }
        }
        
+       if (pcmd->input_dm) {
+               /* pass on the input DM from the cache */
+               dm = pcmd->input_dm;
+               pcmd->input_dm = NULL;
+       }
+       
        return dm;
 }

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

Reply via email to