Fixed crash with ipo'ed collision object
authorDaniel Genrich <daniel.genrich@gmx.net>
Tue, 2 Oct 2007 09:47:08 +0000 (09:47 +0000)
committerDaniel Genrich <daniel.genrich@gmx.net>
Tue, 2 Oct 2007 09:47:08 +0000 (09:47 +0000)
source/blender/blenkernel/BKE_cloth.h
source/blender/blenkernel/intern/cloth.c
source/blender/blenkernel/intern/kdop.c
source/blender/src/headerbuttons.c

index bbdf4bc01c98117688ebcbd98e7aaedf2b44c379..4a160275a996cfc9950d4d8a22ffbfccfe52893f 100644 (file)
@@ -86,12 +86,12 @@ struct DerivedMesh;
 typedef enum 
 {
        CSIMSETT_FLAG_RESET = (1 << 1),         // The CM object requires a reinitializaiton.
-                              CSIMSETT_FLAG_COLLOBJ = (1 << 2),        // object is only collision object, no cloth simulation is done
-                                              CSIMSETT_FLAG_GOAL = (1 << 3),           // we have goals enabled
-                                                              CSIMSETT_FLAG_CCACHE_FREE_ALL = (1 << 4),  // delete all from cache
-                                                                              CSIMSETT_FLAG_CCACHE_FREE_PART = (1 << 5), // delete some part of cache
-                                                                               CSIMSETT_FLAG_TEARING_ENABLED = (1 << 6), // true if tearing is enabled
-                                                                               CSIMSETT_FLAG_CCACHE_PROTECT = (1 << 7), // true if tearing is enabled
+                       CSIMSETT_FLAG_COLLOBJ = (1 << 2),       // object is only collision object, no cloth simulation is done
+                       CSIMSETT_FLAG_GOAL = (1 << 3),          // we have goals enabled
+                       CSIMSETT_FLAG_CCACHE_FREE_ALL = (1 << 4),  // delete all from cache
+                       CSIMSETT_FLAG_CCACHE_FREE_PART = (1 << 5), // delete some part of cache
+                       CSIMSETT_FLAG_TEARING_ENABLED = (1 << 6), // true if tearing is enabled
+                       CSIMSETT_FLAG_CCACHE_PROTECT = (1 << 7), // true if tearing is enabled
 } CSIMSETT_FLAGS;
 
 /* Spring types as defined in the paper.*/
@@ -106,7 +106,7 @@ typedef enum
 typedef enum 
 {
        CSPRING_FLAG_DEACTIVATE = (1 << 1),
-                                  CSPRING_FLAG_NEEDED = (1 << 2), // springs has values to be applied
+       CSPRING_FLAG_NEEDED = (1 << 2), // springs has values to be applied
 } CSPRINGS_FLAGS;
 
 // needed for buttons_object.c
index 940fc8b6c5bd65404d3053916649f376f634e701..35d5771b1355ce98fb797cece7c8751b9c7bf763 100644 (file)
@@ -656,6 +656,7 @@ void clothModifier_do(ClothModifierData *clmd, Object *ob, DerivedMesh *dm,
        
        // only be active during a specific period:
        // that's "first frame" and "last frame" on GUI
+       
        if (!(clmd->sim_parms.flags & CSIMSETT_FLAG_COLLOBJ))
        {
                if(current_time < clmd->sim_parms.firstframe)
@@ -699,7 +700,11 @@ void clothModifier_do(ClothModifierData *clmd, Object *ob, DerivedMesh *dm,
                if ((clmd->clothObject == NULL) || (numverts != clmd->clothObject->numverts) )
                {
                        if(!collobj_from_object (ob, clmd, dm, vertexCos, framenr))
+                       {
+                               clmd->sim_parms.flags |= CSIMSETT_FLAG_COLLOBJ;
+                               cloth_free_modifier(clmd);
                                return;
+                       }
 
                        if(clmd->clothObject == NULL)
                                return;
@@ -712,7 +717,7 @@ void clothModifier_do(ClothModifierData *clmd, Object *ob, DerivedMesh *dm,
                clmd->sim_parms.sim_time = current_time; 
                
                verts = cloth->verts;
-
+               
                for (i = 0; i < clmd->clothObject->numverts; i++, verts++)
                {
                        // Save the previous position. 
@@ -753,24 +758,24 @@ void clothModifier_do(ClothModifierData *clmd, Object *ob, DerivedMesh *dm,
                        {
                                verts = cloth->verts;
                                
-                               /* Force any pinned verts to their constrained location. */
+                               // Force any pinned verts to their constrained location. 
                                for (i = 0; i < clmd->clothObject->numverts; i++, verts++)
                                {
-                                       /* Save the previous position. */
+                                       // Save the previous position. 
                                        VECCOPY (verts->xold, verts->xconst);
                                        VECCOPY (verts->txold, verts->x);
 
-                                       /* Get the current position. */
+                                       // Get the current position. 
                                        VECCOPY (verts->xconst, vertexCos[i]);
                                        Mat4MulVecfl(ob->obmat, verts->xconst);
                                }
 
                                tstart();
 
-                               /* Call the solver. */
+                               // Call the solver.
                                if (solvers [clmd->sim_parms.solver_type].solver)
                                        solvers [clmd->sim_parms.solver_type].solver (ob, framenr, clmd, effectors);
-
+                               
                                tend();
                                printf("Cloth simulation time: %f\n", (float)tval());
 
@@ -801,6 +806,7 @@ void clothModifier_do(ClothModifierData *clmd, Object *ob, DerivedMesh *dm,
                        }
                }
        }
+       
 }
 
 /* frees all */
@@ -815,7 +821,7 @@ void cloth_free_modifier (ClothModifierData *clmd)
        
        if(!(clmd->sim_parms.flags & CSIMSETT_FLAG_CCACHE_PROTECT))
        {
-               // free our frame cache
+               // free our frame cache, TODO: but get to first position before
                clmd->sim_parms.flags |= CSIMSETT_FLAG_CCACHE_FREE_ALL;
                cloth_cache_free(clmd, 0);
        
@@ -848,10 +854,10 @@ void cloth_free_modifier (ClothModifierData *clmd)
                        // we save our faces for collision objects
                        if(cloth->mfaces)
                                MEM_freeN(cloth->mfaces);
-               
+                       /*
                        if(clmd->clothObject->facemarks)
                                MEM_freeN(clmd->clothObject->facemarks);
-                       
+                       */
                        MEM_freeN (cloth);
                        clmd->clothObject = NULL;
                }
@@ -965,8 +971,8 @@ static int collobj_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh
        clmd->clothObject = MEM_callocN (sizeof(Cloth), "cloth");
        if (clmd->clothObject) 
        {
-               clmd->clothObject->old_solver_type = -1;
-               clmd->clothObject->old_collision_type = -1;
+               clmd->clothObject->old_solver_type = 255;
+               clmd->clothObject->old_collision_type = 255;
        }
        else if (clmd->clothObject == NULL) 
        {
@@ -986,8 +992,12 @@ static int collobj_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh
                
                if (clmd->clothObject != NULL) 
                {
-                       mvert = CDDM_get_verts(dm);
+                       if (!dm) return 0;
+                       if (!dm->getNumVerts(dm) || !dm->getNumFaces(dm)) return 0;
+                       
+                       mvert = dm->getVertArray(dm);
                        verts = clmd->clothObject->verts;
+                       numverts = clmd->clothObject->numverts = dm->getNumVerts(dm);
                        
                        for (i = 0; i < numverts; i++, verts++)
                        {
@@ -1004,7 +1014,7 @@ static int collobj_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh
                        clmd->clothObject->tree =  bvh_build(clmd,clmd->coll_parms.epsilon);
                        
                }
-
+               
                return 1;
        default: return 0; // TODO - we do not support changing meshes
        }
@@ -1175,8 +1185,8 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d
        clmd->clothObject = MEM_callocN (sizeof(Cloth), "cloth");
        if (clmd->clothObject) 
        {
-               clmd->clothObject->old_solver_type = -1;
-               clmd->clothObject->old_collision_type = -1;
+               clmd->clothObject->old_solver_type = 255;
+               clmd->clothObject->old_collision_type = 255;
        }
        else if (clmd->clothObject == NULL) 
        {
@@ -1242,7 +1252,7 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d
 
                        clmd->clothObject->tree = bvh_build(clmd, clmd->coll_parms.epsilon);
 
-                       cloth_cache_set_frame(clmd, 1);
+                       // cloth_cache_set_frame(clmd, 1);
                }
 
                return 1;
@@ -1265,7 +1275,7 @@ static void cloth_from_mesh (Object *ob, ClothModifierData *clmd, DerivedMesh *d
 {
        unsigned int numverts = dm->getNumVerts(dm);
        unsigned int numfaces = dm->getNumFaces(dm);
-       MFace *mface = CDDM_get_faces(dm);
+       MFace *mface = dm->getFaceArray(dm);
        unsigned int i = 0;
 
        /* Allocate our vertices.
index 51c571f195962ddc4edc784281f1fcdaa736909e..a2d89be5d0966746928b1ccbd7c59e9ce17c3b7b 100644 (file)
@@ -572,6 +572,7 @@ BVH *bvh_build (ClothModifierData *clmd, float epsilon)
        bvh->flags = 0;
        bvh->leaf_tree = NULL;
        bvh->leaf_root = NULL;
+       bvh->tree = NULL;
 
        bvh->epsilon = epsilon;
        bvh->numfaces = cloth->numfaces;
@@ -581,7 +582,7 @@ BVH *bvh_build (ClothModifierData *clmd, float epsilon)
        bvh->verts = cloth->verts;      
        tree = (Tree *)MEM_callocN(sizeof(Tree), "Tree");
        // TODO: check succesfull alloc
-       BLI_linklist_prepend(&bvh->tree, tree);
+       BLI_linklist_append(&bvh->tree, tree);
 
        nlink = bvh->tree;
 
index 4564db8d9189f0d38f07898a3ea69c7afe0b4c89..617bef705df6011e490ca446fcfb70613b838ae5 100644 (file)
@@ -1067,6 +1067,7 @@ void do_global_buttons(unsigned short event)
                                        else if(nr==ID_LA) idtest= (ID *)add_ipo("LaIpo", nr);
                                        else if(nr==ID_CA) idtest= (ID *)add_ipo("CaIpo", nr);
                                        else if(nr==ID_SO) idtest= (ID *)add_ipo("SndIpo", nr);
+                                       else if(nr==ID_FLUIDSIM) idtest= (ID *)add_ipo("FluidsimIpo", nr);
                                        else error("Warn bugtracker!");
                                }
                                idtest->us--;