[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14160] trunk/blender/source/blender/ blenkernel/intern: Collision Modifier/KDOP: Rearrange things to be more generic.

Daniel Genrich daniel.genrich at gmx.net
Mon Mar 17 22:45:40 CET 2008


Revision: 14160
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14160
Author:   genscher
Date:     2008-03-17 22:45:40 +0100 (Mon, 17 Mar 2008)

Log Message:
-----------
Collision Modifier/KDOP: Rearrange things to be more generic. Also fix possible crash if not enough memory there.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/cloth.c
    trunk/blender/source/blender/blenkernel/intern/collision.c
    trunk/blender/source/blender/blenkernel/intern/kdop.c

Modified: trunk/blender/source/blender/blenkernel/intern/cloth.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/cloth.c	2008-03-17 20:57:16 UTC (rev 14159)
+++ trunk/blender/source/blender/blenkernel/intern/cloth.c	2008-03-17 21:45:40 UTC (rev 14160)
@@ -190,11 +190,6 @@
 	
 	// springs = cloth->springs;
 	// numsprings = cloth->numsprings;
-	
-	bvh->flags = 0;
-	bvh->leaf_tree = NULL;
-	bvh->leaf_root = NULL;
-	bvh->tree = NULL;
 
 	bvh->epsilon = epsilon;
 	bvh->numfaces = cloth->numfaces;
@@ -211,20 +206,9 @@
 		return NULL;
 	}
 	
-	bvh->current_xold = MEM_callocN ( sizeof ( MVert ) * bvh->numverts, "bvh->current_xold" );
-	
-	if (bvh->current_xold == NULL) 
-	{
-		printf("bvh: Out of memory.\n");
-		MEM_freeN(bvh->current_x);
-		MEM_freeN(bvh);
-		return NULL;
-	}
-	
 	for(i = 0; i < bvh->numverts; i++)
 	{
 		VECCOPY(bvh->current_x[i].co, verts[i].tx);
-		VECCOPY(bvh->current_xold[i].co, verts[i].txold);
 	}
 	
 	bvh_build (bvh);

Modified: trunk/blender/source/blender/blenkernel/intern/collision.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/collision.c	2008-03-17 20:57:16 UTC (rev 14159)
+++ trunk/blender/source/blender/blenkernel/intern/collision.c	2008-03-17 21:45:40 UTC (rev 14160)
@@ -86,11 +86,6 @@
 	// in the moment, return zero if no faces there
 	if(!numfaces)
 		return NULL;
-	
-	bvh->flags = 0;
-	bvh->leaf_tree = NULL;
-	bvh->leaf_root = NULL;
-	bvh->tree = NULL;
 
 	bvh->epsilon = epsilon;
 	bvh->numfaces = numfaces;
@@ -103,8 +98,7 @@
 	}
 
 	bvh->numverts = numverts;
-	bvh->current_x = MEM_dupallocN(x);	
-	bvh->current_xold = MEM_dupallocN(x);	
+	bvh->current_x = MEM_dupallocN(x);
 	
 	bvh_build(bvh);
 	
@@ -975,10 +969,13 @@
 	
 	if (collmd->tree) 
 	{
+		/* get pointer to bounding volume hierarchy */
 		BVH *coll_bvh = collmd->tree;
-				
+		
+		/* move object to position (step) in time */
 		collision_move_object(collmd, step + dt, step);
-					
+		
+		/* search for overlapping collision pairs */
 		bvh_traverse((ModifierData *)clmd, (ModifierData *)collmd, cloth_bvh->root, coll_bvh->root, step, cloth_collision_static, 0);
 	}
 	else

Modified: trunk/blender/source/blender/blenkernel/intern/kdop.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/kdop.c	2008-03-17 20:57:16 UTC (rev 14159)
+++ trunk/blender/source/blender/blenkernel/intern/kdop.c	2008-03-17 21:45:40 UTC (rev 14160)
@@ -538,18 +538,32 @@
 	CollisionTree *tree=NULL;
 	LinkNode *nlink = NULL;
 	
+	bvh->flags = 0;
+	bvh->leaf_tree = NULL;
+	bvh->leaf_root = NULL;
+	bvh->tree = NULL;
+	
+	if(!bvh->current_x)
+	{
+		bvh_free(bvh);
+		return;
+	}
+	
+	bvh->current_xold = MEM_dupallocN(bvh->current_x);
+	
 	tree = (CollisionTree *)MEM_callocN(sizeof(CollisionTree), "CollisionTree");
-	// TODO: check succesfull alloc
-	BLI_linklist_append(&bvh->tree, tree);
-
-	nlink = bvh->tree;
-
+	
 	if (tree == NULL) 
 	{
 		printf("bvh_build: Out of memory for nodes.\n");
 		bvh_free(bvh);
 		return;
 	}
+	
+	BLI_linklist_append(&bvh->tree, tree);
+
+	nlink = bvh->tree;
+
 	bvh->root = bvh->tree->link;
 	bvh->root->isleaf = 0;
 	bvh->root->parent = NULL;





More information about the Bf-blender-cvs mailing list