Fix: Allow RNA functions to return collection properties
Possibly broken by acd1b0b7f9.
Though returning a collection property from an RNA function doesn't
seem to have been used before. The mistakes are relatively obvious.
The RNA parameter list data isn't initialized so placement new and
calling the CollectionVector destructor manually are necessary.
This fix is necessary for #135734 which is targeted at 4.4.
Pull Request: https://projects.blender.org/blender/blender/pulls/135746
This commit is contained in:
@@ -3433,12 +3433,20 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA
|
||||
(dparm->prop->arraydimension)) ?
|
||||
"*" :
|
||||
"";
|
||||
fprintf(f,
|
||||
"\t*((%s%s %s*)_retdata) = %s;\n",
|
||||
rna_type_struct(dparm->prop),
|
||||
rna_parameter_type_name(dparm->prop),
|
||||
ptrstr,
|
||||
func->c_ret->identifier);
|
||||
if (dparm->prop->type == PROP_COLLECTION) {
|
||||
/* Placement new is necessary because #ParameterList::data is not initialized. */
|
||||
fprintf(f,
|
||||
"\tnew ((CollectionVector *)_retdata) CollectionVector(std::move(%s));\n",
|
||||
func->c_ret->identifier);
|
||||
}
|
||||
else {
|
||||
fprintf(f,
|
||||
"\t*((%s%s %s*)_retdata) = %s;\n",
|
||||
rna_type_struct(dparm->prop),
|
||||
rna_parameter_type_name(dparm->prop),
|
||||
ptrstr,
|
||||
func->c_ret->identifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6403,7 +6403,8 @@ void RNA_parameter_list_free(ParameterList *parms)
|
||||
void *data = parms->data;
|
||||
for (; parm; parm = parm->next) {
|
||||
if (parm->type == PROP_COLLECTION) {
|
||||
BLI_freelistN(static_cast<ListBase *>(data));
|
||||
CollectionVector *vector = static_cast<CollectionVector *>(data);
|
||||
vector->~CollectionVector();
|
||||
}
|
||||
else if ((parm->flag_parameter & PARM_RNAPTR) && (parm->flag & PROP_THICK_WRAP)) {
|
||||
BLI_assert(parm->type == PROP_POINTER);
|
||||
|
||||
@@ -4699,7 +4699,7 @@ int rna_parameter_size(PropertyRNA *parm)
|
||||
#endif
|
||||
}
|
||||
case PROP_COLLECTION:
|
||||
return sizeof(ListBase);
|
||||
return sizeof(CollectionVector);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user