Fix T55160: crash renaming view layer.
This commit is contained in:
parent
37b947c7ef
commit
7c5e174871
Notes:
blender-bot
2023-02-14 05:51:15 +01:00
Referenced by issue #55161, Outliner Blender File filter ignores libraries Referenced by issue #55163, Visiblity not updated for instanced collections Referenced by issue #55160, Renaming view layer crash
|
@ -31,23 +31,22 @@
|
|||
* \author Joshua Leung
|
||||
*/
|
||||
|
||||
struct AnimData;
|
||||
struct AnimMapper;
|
||||
struct FCurve;
|
||||
struct ID;
|
||||
struct KS_Path;
|
||||
struct KeyingSet;
|
||||
struct ListBase;
|
||||
struct Main;
|
||||
struct AnimData;
|
||||
struct FCurve;
|
||||
struct KeyingSet;
|
||||
struct KS_Path;
|
||||
struct PathResolvedRNA;
|
||||
struct bContext;
|
||||
|
||||
struct PointerRNA;
|
||||
struct PropertyRNA;
|
||||
struct ReportList;
|
||||
struct Scene;
|
||||
struct bAction;
|
||||
struct bActionGroup;
|
||||
struct AnimMapper;
|
||||
struct FCurve;
|
||||
struct bContext;
|
||||
|
||||
/* ************************************* */
|
||||
/* AnimData API */
|
||||
|
@ -119,7 +118,7 @@ void BKE_keyingsets_free(struct ListBase *list);
|
|||
/* Path Fixing API */
|
||||
|
||||
/* Get a "fixed" version of the given path (oldPath) */
|
||||
char *BKE_animsys_fix_rna_path_rename(ID *owner_id, char *old_path, const char *prefix, const char *oldName,
|
||||
char *BKE_animsys_fix_rna_path_rename(struct ID *owner_id, char *old_path, const char *prefix, const char *oldName,
|
||||
const char *newName, int oldSubscript, int newSubscript, bool verify_paths);
|
||||
|
||||
/* Fix all the paths for the given ID + Action */
|
||||
|
@ -132,7 +131,7 @@ void BKE_animdata_fix_paths_rename(struct ID *owner_id, struct AnimData *adt, st
|
|||
bool verify_paths);
|
||||
|
||||
/* Fix all the paths for the entire database... */
|
||||
void BKE_animdata_fix_paths_rename_all(ID *ref_id, const char *prefix, const char *oldName, const char *newName);
|
||||
void BKE_animdata_fix_paths_rename_all(struct ID *ref_id, const char *prefix, const char *oldName, const char *newName);
|
||||
|
||||
/* Fix the path after removing elements that are not ID (e.g., node) */
|
||||
void BKE_animdata_fix_paths_remove(struct ID *id, const char *path);
|
||||
|
|
|
@ -80,6 +80,8 @@ void BKE_view_layer_copy_data(
|
|||
struct ViewLayer *view_layer_dst, const struct ViewLayer *view_layer_src,
|
||||
const int flag);
|
||||
|
||||
void BKE_view_layer_rename(struct Scene *scene, struct ViewLayer *view_layer, const char *name);
|
||||
|
||||
struct LayerCollection *BKE_layer_collection_get_active(struct ViewLayer *view_layer);
|
||||
bool BKE_layer_collection_activate(struct ViewLayer *view_layer, struct LayerCollection *lc);
|
||||
struct LayerCollection *BKE_layer_collection_activate_parent(struct ViewLayer *view_layer, struct LayerCollection *lc);
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "BLI_threads.h"
|
||||
#include "BLT_translation.h"
|
||||
|
||||
#include "BKE_animsys.h"
|
||||
#include "BKE_collection.h"
|
||||
#include "BKE_freestyle.h"
|
||||
#include "BKE_global.h"
|
||||
|
@ -387,6 +388,34 @@ void BKE_view_layer_copy_data(
|
|||
// TODO: not always safe to free BKE_layer_collection_sync(scene_dst, view_layer_dst);
|
||||
}
|
||||
|
||||
void BKE_view_layer_rename(Scene *scene, ViewLayer *view_layer, const char *newname)
|
||||
{
|
||||
char oldname[sizeof(view_layer->name)];
|
||||
|
||||
BLI_strncpy(oldname, view_layer->name, sizeof(view_layer->name));
|
||||
|
||||
BLI_strncpy_utf8(view_layer->name, newname, sizeof(view_layer->name));
|
||||
BLI_uniquename(&scene->view_layers, view_layer, DATA_("ViewLayer"), '.', offsetof(ViewLayer, name), sizeof(view_layer->name));
|
||||
|
||||
if (scene->nodetree) {
|
||||
bNode *node;
|
||||
int index = BLI_findindex(&scene->view_layers, view_layer);
|
||||
|
||||
for (node = scene->nodetree->nodes.first; node; node = node->next) {
|
||||
if (node->type == CMP_NODE_R_LAYERS && node->id == NULL) {
|
||||
if (node->custom1 == index)
|
||||
BLI_strncpy(node->name, view_layer->name, NODE_MAXSTR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* fix all the animation data which may link to this */
|
||||
BKE_animdata_fix_paths_rename_all(NULL, "view_layers", oldname, view_layer->name);
|
||||
|
||||
/* Dependency graph uses view layer name based lookups. */
|
||||
DEG_id_tag_update(&scene->id, 0);
|
||||
}
|
||||
|
||||
/* LayerCollection */
|
||||
|
||||
/**
|
||||
|
|
|
@ -391,10 +391,25 @@ static void namebutton_cb(bContext *C, void *tsep, char *oldname)
|
|||
WM_event_add_notifier(C, NC_GPENCIL | ND_DATA, gpd);
|
||||
break;
|
||||
}
|
||||
case TSE_R_LAYER:
|
||||
{
|
||||
Scene *scene = (Scene *)tselem->id;
|
||||
ViewLayer *view_layer = te->directdata;
|
||||
|
||||
/* Restore old name. */
|
||||
char newname[sizeof(view_layer->name)];
|
||||
BLI_strncpy(newname, view_layer->name, sizeof(view_layer->name));
|
||||
BLI_strncpy(view_layer->name, oldname, sizeof(view_layer->name));
|
||||
|
||||
/* Rename, preserving animation and compositing data. */
|
||||
BKE_view_layer_rename(scene, view_layer, newname);
|
||||
WM_event_add_notifier(C, NC_ID | NA_RENAME, NULL);
|
||||
break;
|
||||
}
|
||||
case TSE_LAYER_COLLECTION:
|
||||
{
|
||||
BLI_libblock_ensure_unique_name(bmain, tselem->id->name);
|
||||
WM_event_add_notifier(C, NC_ID | NA_RENAME, NULL); break;
|
||||
WM_event_add_notifier(C, NC_ID | NA_RENAME, NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -305,7 +305,7 @@ void RNA_def_view_layer(BlenderRNA *brna)
|
|||
PropertyRNA *prop;
|
||||
|
||||
srna = RNA_def_struct(brna, "ViewLayer", NULL);
|
||||
RNA_def_struct_ui_text(srna, "Render Layer", "Render layer");
|
||||
RNA_def_struct_ui_text(srna, "View Layer", "View layer");
|
||||
RNA_def_struct_ui_icon(srna, ICON_RENDER_RESULT);
|
||||
RNA_def_struct_path_func(srna, "rna_ViewLayer_path");
|
||||
RNA_def_struct_idprops_func(srna, "rna_ViewLayer_idprops");
|
||||
|
|
|
@ -1486,27 +1486,7 @@ void rna_ViewLayer_name_set(PointerRNA *ptr, const char *value)
|
|||
{
|
||||
Scene *scene = (Scene *)ptr->id.data;
|
||||
ViewLayer *view_layer = (ViewLayer *)ptr->data;
|
||||
char oldname[sizeof(view_layer->name)];
|
||||
|
||||
BLI_strncpy(oldname, view_layer->name, sizeof(view_layer->name));
|
||||
|
||||
BLI_strncpy_utf8(view_layer->name, value, sizeof(view_layer->name));
|
||||
BLI_uniquename(&scene->view_layers, view_layer, DATA_("ViewLayer"), '.', offsetof(ViewLayer, name), sizeof(view_layer->name));
|
||||
|
||||
if (scene->nodetree) {
|
||||
bNode *node;
|
||||
int index = BLI_findindex(&scene->view_layers, view_layer);
|
||||
|
||||
for (node = scene->nodetree->nodes.first; node; node = node->next) {
|
||||
if (node->type == CMP_NODE_R_LAYERS && node->id == NULL) {
|
||||
if (node->custom1 == index)
|
||||
BLI_strncpy(node->name, view_layer->name, NODE_MAXSTR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* fix all the animation data which may link to this */
|
||||
BKE_animdata_fix_paths_rename_all(NULL, "view_layers", oldname, view_layer->name);
|
||||
BKE_view_layer_rename(scene, view_layer, value);
|
||||
}
|
||||
|
||||
static void rna_SceneRenderView_name_set(PointerRNA *ptr, const char *value)
|
||||
|
@ -3224,7 +3204,7 @@ void rna_def_view_layer_common(StructRNA *srna, int scene)
|
|||
prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
|
||||
if (scene) RNA_def_property_string_funcs(prop, NULL, NULL, "rna_ViewLayer_name_set");
|
||||
else RNA_def_property_string_sdna(prop, NULL, "name");
|
||||
RNA_def_property_ui_text(prop, "Name", "Render layer name");
|
||||
RNA_def_property_ui_text(prop, "Name", "View layer name");
|
||||
RNA_def_struct_name_property(srna, prop);
|
||||
if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
|
||||
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
||||
|
|
Loading…
Reference in New Issue