Skip to content
Snippets Groups Projects
Commit edeef8bc authored by Brecht Van Lommel's avatar Brecht Van Lommel
Browse files

Revert revision 30441: [#22876] Add new scene, stacker ".00" bug

This commit broke unique datablock naming, tried to fix it properly but the
code here is too tricky to change now, will just reopen the bug report.
parent ea008f86
Branches
Tags
No related merge requests found
...@@ -63,7 +63,7 @@ void free_libblock_us(struct ListBase *lb, void *idv); ...@@ -63,7 +63,7 @@ void free_libblock_us(struct ListBase *lb, void *idv);
void free_main(struct Main *mainvar); void free_main(struct Main *mainvar);
void tag_main(struct Main *mainvar, int tag); void tag_main(struct Main *mainvar, int tag);
int splitIDname(char *name, char *left, int *nr); void splitIDname(char *name, char *left, int *nr);
void rename_id(struct ID *id, char *name); void rename_id(struct ID *id, char *name);
void test_idbutton(char *name); void test_idbutton(char *name);
void text_idbutton(struct ID *id, char *text); void text_idbutton(struct ID *id, char *text);
...@@ -85,3 +85,4 @@ void set_free_windowmanager_cb(void (*func)(struct bContext *, struct wmWindowMa ...@@ -85,3 +85,4 @@ void set_free_windowmanager_cb(void (*func)(struct bContext *, struct wmWindowMa
#define ID_FALLBACK_NAME "Untitled" #define ID_FALLBACK_NAME "Untitled"
#endif #endif
...@@ -995,7 +995,7 @@ void IMAnames_to_pupstring(char **str, char *title, char *extraops, ListBase *lb ...@@ -995,7 +995,7 @@ void IMAnames_to_pupstring(char **str, char *title, char *extraops, ListBase *lb
/* used by buttons.c library.c mball.c */ /* used by buttons.c library.c mball.c */
int splitIDname(char *name, char *left, int *nr) void splitIDname(char *name, char *left, int *nr)
{ {
int a; int a;
...@@ -1003,21 +1003,19 @@ int splitIDname(char *name, char *left, int *nr) ...@@ -1003,21 +1003,19 @@ int splitIDname(char *name, char *left, int *nr)
strncpy(left, name, 21); strncpy(left, name, 21);
a= strlen(name); a= strlen(name);
if(a>1 && name[a-1]=='.') return a; if(a>1 && name[a-1]=='.') return;
while(a--) { while(a--) {
if( name[a]=='.' ) { if( name[a]=='.' ) {
left[a]= 0; left[a]= 0;
*nr= atol(name+a+1); *nr= atol(name+a+1);
return a; return;
} }
if( isdigit(name[a])==0 ) break; if( isdigit(name[a])==0 ) break;
left[a]= 0; left[a]= 0;
} }
strcpy(left, name); strcpy(left, name);
return a;
} }
static void sort_alpha_id(ListBase *lb, ID *id) static void sort_alpha_id(ListBase *lb, ID *id)
...@@ -1079,7 +1077,8 @@ static ID *is_dupid(ListBase *lb, ID *id, char *name) ...@@ -1079,7 +1077,8 @@ static ID *is_dupid(ListBase *lb, ID *id, char *name)
static int check_for_dupid(ListBase *lb, ID *id, char *name) static int check_for_dupid(ListBase *lb, ID *id, char *name)
{ {
ID *idtest; ID *idtest;
int nr= 0, nrtest, a, left_len; int nr= 0, nrtest, a;
const int maxtest=32;
char left[32], leftest[32], in_use[32]; char left[32], leftest[32], in_use[32];
/* make sure input name is terminated properly */ /* make sure input name is terminated properly */
...@@ -1096,25 +1095,22 @@ static int check_for_dupid(ListBase *lb, ID *id, char *name) ...@@ -1096,25 +1095,22 @@ static int check_for_dupid(ListBase *lb, ID *id, char *name)
/* we have a dup; need to make a new name */ /* we have a dup; need to make a new name */
/* quick check so we can reuse one of first 32 ids if vacant */ /* quick check so we can reuse one of first 32 ids if vacant */
memset(in_use, 0, sizeof(in_use)); memset(in_use, 0, maxtest);
/* get name portion, number portion ("name.number") */ /* get name portion, number portion ("name.number") */
left_len= splitIDname(name, left, &nr); splitIDname( name, left, &nr);
/* if new name will be too long, truncate it */ /* if new name will be too long, truncate it */
if(nr>999 && strlen(left)>16) left[16]= 0; if(nr>999 && strlen(left)>16) left[16]= 0;
else if(strlen(left)>17) left[17]= 0; else if(strlen(left)>17) left[17]= 0;
if(left_len) {
for( idtest = lb->first; idtest; idtest = idtest->next ) { for( idtest = lb->first; idtest; idtest = idtest->next ) {
if( (id != idtest) && if( id != idtest && idtest->lib == NULL ) {
(idtest->lib == NULL) && splitIDname(idtest->name+2, leftest, &nrtest);
(*name == *(idtest->name+2)) && /* if base names match... */
(strncmp(name, idtest->name+2, left_len)==0) && /* optimized */
(splitIDname(idtest->name+2, leftest, &nrtest) == left_len) if( *left == *leftest && strcmp(left, leftest)==0 ) {
if(nrtest < maxtest)
) {
if(nrtest < sizeof(in_use))
in_use[nrtest]= 1; /* mark as used */ in_use[nrtest]= 1; /* mark as used */
if(nr <= nrtest) if(nr <= nrtest)
nr= nrtest+1; /* track largest unused */ nr= nrtest+1; /* track largest unused */
...@@ -1123,7 +1119,7 @@ static int check_for_dupid(ListBase *lb, ID *id, char *name) ...@@ -1123,7 +1119,7 @@ static int check_for_dupid(ListBase *lb, ID *id, char *name)
} }
/* decide which value of nr to use */ /* decide which value of nr to use */
for(a=0; a < sizeof(in_use); a++) { for(a=0; a<maxtest; a++) {
if(a>=nr) break; /* stop when we've check up to biggest */ if(a>=nr) break; /* stop when we've check up to biggest */
if( in_use[a]==0 ) { /* found an unused value */ if( in_use[a]==0 ) { /* found an unused value */
nr = a; nr = a;
...@@ -1133,9 +1129,8 @@ static int check_for_dupid(ListBase *lb, ID *id, char *name) ...@@ -1133,9 +1129,8 @@ static int check_for_dupid(ListBase *lb, ID *id, char *name)
/* If the original name has no numeric suffix, /* If the original name has no numeric suffix,
* rather than just chopping and adding numbers, * rather than just chopping and adding numbers,
* shave off the end chars until we have a unique name. * shave off the end chars until we have a unique name */
* Check the null terminators match as well so we dont get Cube.000 -> Cube.00 */ if (nr==0) {
if (nr==0 && name[left_len] == left[left_len]) {
int len = strlen(name)-1; int len = strlen(name)-1;
idtest= is_dupid(lb, id, name); idtest= is_dupid(lb, id, name);
...@@ -1394,3 +1389,4 @@ void rename_id(ID *id, char *name) ...@@ -1394,3 +1389,4 @@ void rename_id(ID *id, char *name)
new_id(lb, id, name); new_id(lb, id, name);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment