diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2019-02-06 22:59:29 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2019-02-06 23:13:52 +0300 |
commit | ac9daf3a27df8693fc2a6852d52bea5c33ca6c56 (patch) | |
tree | 7c9a0e27e7a97996f0251d8602645af909fc7926 /source/blender/makesrna/intern/rna_depsgraph.c | |
parent | 766741b0aa8c7325bddb0e68c5af7b8610720879 (diff) |
Fix (unreported) crash when iterating on depsgraph instances from RNA.
This is a follow-up to rBb44e6f2b3d32, for some reason that issue was
not detected back then: in some cases, DEG_iterator_objects_next() will
free the temp list of dupli objects once it does not need it anymore,
henceforth freeing the dupli_object_current memory of the DEGObjectIterData
that we are storing in the RNA_Depsgraph_Instances_Iterator struct.
And yes, the uglyness of that hack is getting even better now...
Found while trying to export dupliobjects with FBX...
Diffstat (limited to 'source/blender/makesrna/intern/rna_depsgraph.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_depsgraph.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_depsgraph.c b/source/blender/makesrna/intern/rna_depsgraph.c index 6f930d7569a..1a2ecc11505 100644 --- a/source/blender/makesrna/intern/rna_depsgraph.c +++ b/source/blender/makesrna/intern/rna_depsgraph.c @@ -301,6 +301,7 @@ typedef struct RNA_Depsgraph_Instances_Iterator { BLI_Iterator iterators[2]; DEGObjectIterData deg_data[2]; + DupliObject dupli_object_current[2]; int counter; } RNA_Depsgraph_Instances_Iterator; @@ -331,6 +332,13 @@ static void rna_Depsgraph_object_instances_next(CollectionPropertyIterator *iter di_it->iterators[di_it->counter % 2].data = &di_it->deg_data[di_it->counter % 2]; DEG_iterator_objects_next(&di_it->iterators[di_it->counter % 2]); + /* Dupli_object_current is also temp memory generated during the iterations, + * it may be freed when last item has been iterated, so we have same issue as with the iterator itself: + * we need to keep a local copy, which memory remains valid a bit longer, for python accesses to work. */ + if (di_it->deg_data[di_it->counter % 2].dupli_object_current != NULL) { + di_it->dupli_object_current[di_it->counter % 2] = *di_it->deg_data[di_it->counter % 2].dupli_object_current; + di_it->deg_data[di_it->counter % 2].dupli_object_current = &di_it->dupli_object_current[di_it->counter % 2]; + } iter->valid = di_it->iterators[di_it->counter % 2].valid; } |