forked from bartvdbraak/blender
RNA: keep structs_map valid w/ ID duplicate & free
This commit is contained in:
parent
8899ac1550
commit
4761dea573
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user