[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16924] trunk/blender/source/blender/ blenkernel/intern/pointcache.c: Fix for part of bug #17759: point cache clearing did too much, also

Brecht Van Lommel brecht at blender.org
Sat Oct 4 23:26:48 CEST 2008


Revision: 16924
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16924
Author:   blendix
Date:     2008-10-04 23:26:48 +0200 (Sat, 04 Oct 2008)

Log Message:
-----------
Fix for part of bug #17759: point cache clearing did too much, also
clearing other physics systems on the same object.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/pointcache.c

Modified: trunk/blender/source/blender/blenkernel/intern/pointcache.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/pointcache.c	2008-10-04 21:04:16 UTC (rev 16923)
+++ trunk/blender/source/blender/blenkernel/intern/pointcache.c	2008-10-04 21:26:48 UTC (rev 16924)
@@ -70,6 +70,12 @@
 #include <unistd.h>
 #endif
 
+#ifdef _WIN32
+#ifndef snprintf
+#define snprintf _snprintf
+#endif
+#endif
+
 /* Creating ID's */
 
 void BKE_ptcache_id_from_softbody(PTCacheID *pid, Object *ob, SoftBody *sb)
@@ -164,6 +170,9 @@
 	- stack_index: index in the modifier stack. we can have cache for more then one stack_index
 */
 
+#define MAX_PTCACHE_PATH FILE_MAX
+#define MAX_PTCACHE_FILE ((FILE_MAXDIR+FILE_MAXFILE)*2)
+
 static int ptcache_path(PTCacheID *pid, char *filename)
 {
 	Library *lib;
@@ -172,7 +181,7 @@
 	lib= (pid)? pid->ob->id.lib: NULL;
 
 	if (G.relbase_valid || lib) {
-		char file[FILE_MAX]; /* we dont want the dir, only the file */
+		char file[MAX_PTCACHE_PATH]; /* we dont want the dir, only the file */
 		char *blendfilename;
 
 		blendfilename= (lib)? lib->filename: G.sce;
@@ -184,7 +193,7 @@
 		if (i > 6)
 			file[i-6] = '\0';
 		
-		sprintf(filename, "//"PTCACHE_PATH"%s", file); /* add blend file name to pointcache dir */
+		snprintf(filename, MAX_PTCACHE_PATH, "//"PTCACHE_PATH"%s", file); /* add blend file name to pointcache dir */
 		BLI_convertstringcode(filename, blendfilename);
 		BLI_add_slash(filename);
 		return strlen(filename);
@@ -192,7 +201,7 @@
 	
 	/* use the temp path. this is weak but better then not using point cache at all */
 	/* btempdir is assumed to exist and ALWAYS has a trailing slash */
-	sprintf(filename, "%s"PTCACHE_PATH"%d", btempdir, abs(getpid()));
+	snprintf(filename, MAX_PTCACHE_PATH, "%s"PTCACHE_PATH"%d", btempdir, abs(getpid()));
 	BLI_add_slash(filename);
 	return strlen(filename);
 }
@@ -215,13 +224,13 @@
 	idname = (pid->ob->id.name+2);
 	/* convert chars to hex so they are always a valid filename */
 	while('\0' != *idname) {
-		sprintf(newname, "%02X", (char)(*idname++));
+		snprintf(newname, MAX_PTCACHE_FILE, "%02X", (char)(*idname++));
 		newname+=2;
 		len += 2;
 	}
 	
 	if (do_ext) {
-		sprintf(newname, "_%06d_%02d"PTCACHE_EXT, cfra, pid->stack_index); /* always 6 chars */
+		snprintf(newname, MAX_PTCACHE_FILE, "_%06d_%02d"PTCACHE_EXT, cfra, pid->stack_index); /* always 6 chars */
 		len += 16;
 	}
 	
@@ -290,9 +299,10 @@
 	/* mode is same as fopen's modes */
 	DIR *dir; 
 	struct dirent *de;
-	char path[FILE_MAX];
-	char filename[(FILE_MAXDIR+FILE_MAXFILE)*2];
-	char path_full[(FILE_MAXDIR+FILE_MAXFILE)*2];
+	char path[MAX_PTCACHE_PATH];
+	char filename[MAX_PTCACHE_FILE];
+	char path_full[MAX_PTCACHE_FILE];
+	char ext[MAX_PTCACHE_PATH];
 
 	if(!pid->cache)
 		return;
@@ -315,9 +325,11 @@
 		dir = opendir(path);
 		if (dir==NULL)
 			return;
+
+		snprintf(ext, sizeof(ext), "_%02d"PTCACHE_EXT, pid->stack_index);
 		
 		while ((de = readdir(dir)) != NULL) {
-			if (strstr(de->d_name, PTCACHE_EXT)) { /* do we have the right extension?*/
+			if (strstr(de->d_name, ext)) { /* do we have the right extension?*/
 				if (strncmp(filename, de->d_name, len ) == 0) { /* do we have the right prefix */
 					if (mode == PTCACHE_CLEAR_ALL) {
 						BLI_join_dirfile(path_full, path, de->d_name);
@@ -326,8 +338,9 @@
 						/* read the number of the file */
 						int frame, len2 = strlen(de->d_name);
 						char num[7];
+
 						if (len2 > 15) { /* could crash if trying to copy a string out of this range*/
-							strncpy(num, de->d_name + (strlen(de->d_name) - 15), 6);
+							BLI_strncpy(num, de->d_name + (strlen(de->d_name) - 15), sizeof(num));
 							frame = atoi(num);
 							
 							if((mode==PTCACHE_CLEAR_BEFORE && frame < cfra)	|| 
@@ -353,7 +366,7 @@
 
 int BKE_ptcache_id_exist(PTCacheID *pid, int cfra)
 {
-	char filename[(FILE_MAXDIR+FILE_MAXFILE)*2];
+	char filename[MAX_PTCACHE_FILE];
 
 	if(!pid->cache)
 		return 0;
@@ -499,8 +512,8 @@
 /* Use this when quitting blender, with unsaved files */
 void BKE_ptcache_remove(void)
 {
-	char path[FILE_MAX];
-	char path_full[FILE_MAX];
+	char path[MAX_PTCACHE_PATH];
+	char path_full[MAX_PTCACHE_PATH];
 	int rmdir = 1;
 	
 	ptcache_path(NULL, path);





More information about the Bf-blender-cvs mailing list