diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-08-23 07:14:55 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-08-23 07:14:55 +0300 |
commit | 4761dea573f6fa9a57150596098c17f723d3a49f (patch) | |
tree | 616788f3746d32d1a936466246b53a852fc1469c /source/blender | |
parent | 8899ac1550648ea6942a581e3939aa70b00e4915 (diff) |
RNA: keep structs_map valid w/ ID duplicate & free
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/node.c | 6 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_define.h | 4 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_define.c | 34 |
3 files changed, 30 insertions, 14 deletions
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 3836d154a7b..54afe76ec07 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -2235,7 +2235,7 @@ static void ntree_interface_type_create(bNodeTree *ntree) /* register a subtype of PropertyGroup */ srna = RNA_def_struct_ptr(&BLENDER_RNA, identifier, &RNA_PropertyGroup); RNA_def_struct_ui_text(srna, name, description); - RNA_def_struct_duplicate_pointers(srna); + RNA_def_struct_duplicate_pointers(&BLENDER_RNA, srna); /* associate the RNA type with the node tree */ ntree->interface_type = srna; @@ -2274,10 +2274,10 @@ StructRNA *ntreeInterfaceTypeGet(bNodeTree *ntree, int create) ntree_interface_identifier(ntree, base, identifier, sizeof(identifier), name, description); /* rename the RNA type */ - RNA_def_struct_free_pointers(srna); + RNA_def_struct_free_pointers(&BLENDER_RNA, srna); RNA_def_struct_identifier(&BLENDER_RNA, srna, identifier); RNA_def_struct_ui_text(srna, name, description); - RNA_def_struct_duplicate_pointers(srna); + RNA_def_struct_duplicate_pointers(&BLENDER_RNA, srna); } } else if (create) { diff --git a/source/blender/makesrna/RNA_define.h b/source/blender/makesrna/RNA_define.h index b49cea0263b..42ffe774720 100644 --- a/source/blender/makesrna/RNA_define.h +++ b/source/blender/makesrna/RNA_define.h @@ -217,8 +217,8 @@ void RNA_enum_item_end(EnumPropertyItem **items, int *totitem); /* Memory management */ -void RNA_def_struct_duplicate_pointers(StructRNA *srna); -void RNA_def_struct_free_pointers(StructRNA *srna); +void RNA_def_struct_duplicate_pointers(BlenderRNA *brna, StructRNA *srna); +void RNA_def_struct_free_pointers(BlenderRNA *brna, StructRNA *srna); void RNA_def_func_duplicate_pointers(FunctionRNA *func); void RNA_def_func_free_pointers(FunctionRNA *func); void RNA_def_property_duplicate_pointers(StructOrFunctionRNA *cont_, PropertyRNA *prop); diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index b10a2b33317..cbe9684e821 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -156,7 +156,7 @@ static void rna_brna_structs_remove_and_free(BlenderRNA *brna, StructRNA *srna) } } - RNA_def_struct_free_pointers(srna); + RNA_def_struct_free_pointers(NULL, srna); if (srna->flag & STRUCT_RUNTIME) { rna_freelinkN(&brna->structs, srna); @@ -3313,21 +3313,37 @@ void RNA_enum_item_end(EnumPropertyItem **items, int *totitem) /* Memory management */ #ifdef RNA_RUNTIME -void RNA_def_struct_duplicate_pointers(StructRNA *srna) +void RNA_def_struct_duplicate_pointers(BlenderRNA *brna, StructRNA *srna) { - if (srna->identifier) srna->identifier = BLI_strdup(srna->identifier); - if (srna->name) srna->name = BLI_strdup(srna->name); - if (srna->description) srna->description = BLI_strdup(srna->description); + if (srna->identifier) { + srna->identifier = BLI_strdup(srna->identifier); + BLI_ghash_replace_key(brna->structs_map, (void *)srna->identifier); + } + if (srna->name) { + srna->name = BLI_strdup(srna->name); + } + if (srna->description) { + srna->description = BLI_strdup(srna->description); + } srna->flag |= STRUCT_FREE_POINTERS; } -void RNA_def_struct_free_pointers(StructRNA *srna) +void RNA_def_struct_free_pointers(BlenderRNA *brna, StructRNA *srna) { if (srna->flag & STRUCT_FREE_POINTERS) { - if (srna->identifier) MEM_freeN((void *)srna->identifier); - if (srna->name) MEM_freeN((void *)srna->name); - if (srna->description) MEM_freeN((void *)srna->description); + if (srna->identifier) { + if (brna != NULL) { + BLI_ghash_remove(brna->structs_map, (void *)srna->identifier, NULL, NULL); + } + MEM_freeN((void *)srna->identifier); + } + if (srna->name) { + MEM_freeN((void *)srna->name); + } + if (srna->description) { + MEM_freeN((void *)srna->description); + } } } |