[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27294] trunk/blender/source/blender: disallow naming ID datablocks an empty string, this wont work, you cant select them in the ID user input and it can mess up writing files based on names .

Campbell Barton ideasman42 at gmail.com
Sat Mar 6 19:21:58 CET 2010


Revision: 27294
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27294
Author:   campbellbarton
Date:     2010-03-06 19:21:57 +0100 (Sat, 06 Mar 2010)

Log Message:
-----------
disallow naming ID datablocks an empty string, this wont work, you cant select them in the ID user input and it can mess up writing files based on names.
also fixed some warnings.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_library.h
    trunk/blender/source/blender/blenkernel/intern/library.c
    trunk/blender/source/blender/editors/screen/screendump.c
    trunk/blender/source/blender/editors/sculpt_paint/sculpt.c

Modified: trunk/blender/source/blender/blenkernel/BKE_library.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_library.h	2010-03-06 13:43:47 UTC (rev 27293)
+++ trunk/blender/source/blender/blenkernel/BKE_library.h	2010-03-06 18:21:57 UTC (rev 27294)
@@ -51,7 +51,6 @@
 int id_copy(struct ID *id, struct ID **newid, int test);
 int id_unlink(struct ID *id, int test);
 
-int check_for_dupid(struct ListBase *lb, struct ID *id, char *name);
 int new_id(struct ListBase *lb, struct ID *id, const char *name);
 
 struct ListBase *wich_libbase(struct Main *mainlib, short type);
@@ -82,5 +81,8 @@
 
 void set_free_windowmanager_cb(void (*func)(struct bContext *, struct wmWindowManager *) );
 
+/* use when "" is given to new_id() */
+#define ID_FALLBACK_NAME "Untitled"
+
 #endif
 

Modified: trunk/blender/source/blender/blenkernel/intern/library.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/library.c	2010-03-06 13:43:47 UTC (rev 27293)
+++ trunk/blender/source/blender/blenkernel/intern/library.c	2010-03-06 18:21:57 UTC (rev 27294)
@@ -1093,15 +1093,16 @@
  * id is NULL;
  */
 
-int check_for_dupid(ListBase *lb, ID *id, char *name)
+static int check_for_dupid(ListBase *lb, ID *id, char *name)
 {
 	ID *idtest;
 	int nr= 0, nrtest, a;
 	const int maxtest=32;
 	char left[32], leftest[32], in_use[32];
-	
+
 	/* make sure input name is terminated properly */
-	if( strlen(name) > 21 ) name[21]= 0;
+	/* if( strlen(name) > 21 ) name[21]= 0; */
+	/* removed since this is only ever called from one place - campbell */
 
 	while (1) {
 
@@ -1184,28 +1185,30 @@
 {
 	int result;
 	char name[22];
-	
+
 	/* if library, don't rename */
 	if(id->lib) return 0;
 
 	/* if no libdata given, look up based on ID */
 	if(lb==NULL) lb= wich_libbase(G.main, GS(id->name));
 
-	if(tname==0) {	/* if no name given, use name of current ID */
-		strncpy(name, id->name+2, 21);
-		result= strlen(id->name+2);
-	}
-	else { /* else make a copy (tname args can be const) */
-		strncpy(name, tname, 21);
-		result= strlen(tname);
-	}
+	/* if no name given, use name of current ID
+	 * else make a copy (tname args can be const) */
+	if(tname==NULL)
+		tname= id->name+2;
 
-	/* if result > 21, strncpy don't put the final '\0' to name. */
-	if( result >= 21 ) name[21]= 0;
+	strncpy(name, tname, sizeof(name)-1);
 
-	result = check_for_dupid( lb, id, name );
-	strcpy( id->name+2, name );
+	/* if result > 21, strncpy don't put the final '\0' to name.
+	 * easier to assign each time then to check if its needed */
+	name[sizeof(name)-1]= 0;
 
+	if(name[0] == '\0')
+		strcpy(name, ID_FALLBACK_NAME);
+
+	result = check_for_dupid(lb, id, name);
+	strcpy(id->name+2, name);
+
 	/* This was in 2.43 and previous releases
 	 * however all data in blender should be sorted, not just duplicate names
 	 * sorting should not hurt, but noting just incause it alters the way other
@@ -1393,7 +1396,7 @@
 void rename_id(ID *id, char *name)
 {
 	ListBase *lb;
-	
+
 	strncpy(id->name+2, name, 21);
 	lb= wich_libbase(G.main, GS(id->name) );
 	

Modified: trunk/blender/source/blender/editors/screen/screendump.c
===================================================================
--- trunk/blender/source/blender/editors/screen/screendump.c	2010-03-06 13:43:47 UTC (rev 27293)
+++ trunk/blender/source/blender/editors/screen/screendump.c	2010-03-06 18:21:57 UTC (rev 27294)
@@ -126,7 +126,7 @@
 
 	if (*dumpsx && *dumpsy) {
 		
-		dumprect= MEM_mallocN(sizeof(int) * dumpsx[0] * dumpsy[0], "dumprect");
+		dumprect= MEM_mallocN(sizeof(int) * (*dumpsx) * (*dumpsy), "dumprect");
 		glReadBuffer(GL_FRONT);
 		glReadPixels(x, y, *dumpsx, *dumpsy, GL_RGBA, GL_UNSIGNED_BYTE, dumprect);
 		glFinish();

Modified: trunk/blender/source/blender/editors/sculpt_paint/sculpt.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/sculpt.c	2010-03-06 13:43:47 UTC (rev 27293)
+++ trunk/blender/source/blender/editors/sculpt_paint/sculpt.c	2010-03-06 18:21:57 UTC (rev 27294)
@@ -252,10 +252,8 @@
 #endif
 
 	view3d_calculate_clipping(bb, planes, &mats, &rect);
+	mul_m4_fl(planes, -1.0f);
 
-	for(i = 0; i < 16; ++i)
-		((float*)planes)[i] = -((float*)planes)[i];
-
 	MEM_freeN(bb);
 
 	/* clear redraw flag from nodes */





More information about the Bf-blender-cvs mailing list