[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12188] branches/cloth/blender/source/ blender: Fixed crash with ipo'ed collision object

Daniel Genrich daniel.genrich at gmx.net
Tue Oct 2 11:47:08 CEST 2007


Revision: 12188
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12188
Author:   genscher
Date:     2007-10-02 11:47:08 +0200 (Tue, 02 Oct 2007)

Log Message:
-----------
Fixed crash with ipo'ed collision object

Modified Paths:
--------------
    branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h
    branches/cloth/blender/source/blender/blenkernel/intern/cloth.c
    branches/cloth/blender/source/blender/blenkernel/intern/kdop.c
    branches/cloth/blender/source/blender/src/headerbuttons.c

Modified: branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h	2007-10-02 09:11:50 UTC (rev 12187)
+++ branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h	2007-10-02 09:47:08 UTC (rev 12188)
@@ -86,12 +86,12 @@
 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 
 {
 	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

Modified: branches/cloth/blender/source/blender/blenkernel/intern/cloth.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/cloth.c	2007-10-02 09:11:50 UTC (rev 12187)
+++ branches/cloth/blender/source/blender/blenkernel/intern/cloth.c	2007-10-02 09:47:08 UTC (rev 12188)
@@ -656,6 +656,7 @@
 	
 	// 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 @@
 		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 @@
 		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 @@
 			{
 				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 @@
 			}
 		}
 	}
+	
 }
 
 /* frees all */
@@ -815,7 +821,7 @@
 	
 	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 @@
 			// 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 @@
 	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 @@
 		
 		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 @@
 			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 @@
 	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 @@
 
 			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 @@
 {
 	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.

Modified: branches/cloth/blender/source/blender/blenkernel/intern/kdop.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/kdop.c	2007-10-02 09:11:50 UTC (rev 12187)
+++ branches/cloth/blender/source/blender/blenkernel/intern/kdop.c	2007-10-02 09:47:08 UTC (rev 12188)
@@ -572,6 +572,7 @@
 	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->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;
 

Modified: branches/cloth/blender/source/blender/src/headerbuttons.c
===================================================================
--- branches/cloth/blender/source/blender/src/headerbuttons.c	2007-10-02 09:11:50 UTC (rev 12187)
+++ branches/cloth/blender/source/blender/src/headerbuttons.c	2007-10-02 09:47:08 UTC (rev 12188)
@@ -1067,6 +1067,7 @@
 					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--;





More information about the Bf-blender-cvs mailing list