Versioning: add renaming utility function

Avoids accidents creating duplicate names.

Also ensure screens are sorted on rename.
This commit is contained in:
Campbell Barton 2019-01-30 09:36:38 +11:00
parent 7894d6c6f1
commit a1ae04d15a
Notes: blender-bot 2023-02-14 08:06:35 +01:00
Referenced by issue #62167, Switch to wireframe view in EVEE shuts down program
Referenced by issue #61460, Crash: Stereoscopy + Desnoising + GPU crashes
Referenced by issue #61162, Fluid viscosity doesn't work
Referenced by issue #61119, Sculpt mode ignores shape key when the object has a Mask modifier.
Referenced by issue #61034, Keyframeing outliner "view in..." crashing blender
Referenced by issue #61035, Draw manager crash opening file with curves
Referenced by issue #61039, Crash switching to wire shading with smoke simulation
Referenced by issue #61043, Blender crashes on VSE zoom / scroll timeline sometimes
Referenced by issue #61023, Workbench shading bugs out when using partially transparent materials,studio lighting and view clipping at the same time.
Referenced by issue #61028, Solid View not displayed and crash in wireframe view
Referenced by issue #61009,  'Open Recent' remembers 'Load UI' setting from last file opening
Referenced by issue #61014, Assert adding a driver that uses a single property of a scene ID
Referenced by issue #61016, Camera's should have selectable focus objects while in the workbench render engine
Referenced by issue #60713, EEVEE crashes during shader compilation
Referenced by issue #60660, TEXTURE PAINT tab BUG- Undo a simple PAINT operation using CTRL-Z and it removes entire TEXTURE IMAGE-Workarounds and Thorough Steps to Repeatability BELOW.
Referenced by issue #60536, Crashes after 2nd time rendering scene with GPU Compute
Referenced by issue #58710, Eevee material preview white
1 changed files with 30 additions and 10 deletions

View File

@ -114,6 +114,33 @@ void BLO_update_defaults_userpref_blend(void)
BKE_keyconfig_pref_set_select_mouse(&U, 0, true);
}
/**
* Rename if the ID doesn't exist.
*/
static ID *rename_id_for_versioning(Main *bmain, const short id_type, const char *name_src, const char *name_dst)
{
/* We can ignore libraries */
ListBase *lb = which_libbase(bmain, id_type);
ID *id = NULL;
for (ID *idtest = lb->first; idtest; idtest = idtest->next) {
if (idtest->lib == NULL) {
if (STREQ(idtest->name + 2, name_src)) {
id = idtest;
}
if (STREQ(idtest->name + 2, name_dst)) {
return NULL;
}
}
}
if (id != NULL) {
BLI_strncpy(id->name + 2, name_dst, sizeof(id->name) - 2);
/* We know it's unique, this just sorts. */
BLI_libblock_ensure_unique_name(bmain, id->name);
}
return id;
}
/**
* Update defaults in startup.blend, without having to save and embed the file.
* This function can be emptied each time the startup.blend is updated. */
@ -176,6 +203,7 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
WorkSpaceLayout *layout = BKE_workspace_hook_layout_for_workspace_get(win->workspace_hook, workspace);
bScreen *screen = layout->screen;
BLI_strncpy(screen->id.name + 2, workspace->id.name + 2, sizeof(screen->id.name) - 2);
BLI_libblock_ensure_unique_name(bmain, screen->id.name);
}
}
@ -300,16 +328,8 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
}
/* Rename lamp objects. */
for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
if (STREQ(ob->id.name, "OBLamp")) {
STRNCPY(ob->id.name, "OBLight");
}
}
for (Lamp *lamp = bmain->lamp.first; lamp; lamp = lamp->id.next) {
if (STREQ(lamp->id.name, "LALamp")) {
STRNCPY(lamp->id.name, "LALight");
}
}
rename_id_for_versioning(bmain, ID_OB, "Lamp", "Light");
rename_id_for_versioning(bmain, ID_LA, "Lamp", "Light");
for (Mesh *mesh = bmain->mesh.first; mesh; mesh = mesh->id.next) {
/* Match default for new meshes. */