diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-07-03 16:15:11 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-07-03 17:32:13 +0300 |
commit | 21668359b79bd4a44a1f34e479a7bd8072ecdc69 (patch) | |
tree | 04380c4a057651c768eb00f8b81015239274f2d9 /source/blender/depsgraph/intern/builder/deg_builder_relations.cc | |
parent | 5b2705adf659455399cecf873f7548e5e293f521 (diff) |
Fix T66234: Issue on switching material mode between Object and Data
The root of the issue comes to the fact that part of dependency graph
is being removed, without doing any further remapping.
This was happening because only materials used by objects were pulled
in, so when material mode is changed some material became unused and
removed from the dependency graph and freed, causing object or its
data to point to a freed memory in its materials array.
Simplest and safest way to solve this is to pull materials referenced
by both object and object data. This causes somewhat higher memory
usage but keeps evaluated state of scene in an always consistent state,
without any need to tag/update object's data on material mode change.
Don't think it is a problem in practice.
Reviewers: brecht, fclem
Reviewed By: brecht, fclem
Differential Revision: https://developer.blender.org/D5172
Diffstat (limited to 'source/blender/depsgraph/intern/builder/deg_builder_relations.cc')
-rw-r--r-- | source/blender/depsgraph/intern/builder/deg_builder_relations.cc | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc index c2216e068fc..d2f06136b7e 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc @@ -751,6 +751,12 @@ void DepsgraphRelationBuilder::build_object_data(Object *object) add_relation(key_key, geometry_key, "Shapekeys"); build_nested_shapekey(&object->id, key); } + /* Materials. */ + Material ***materials_ptr = give_matarar(object); + if (materials_ptr != NULL) { + short *num_materials_ptr = give_totcolp(object); + build_materials(*materials_ptr, *num_materials_ptr); + } } void DepsgraphRelationBuilder::build_object_data_camera(Object *object) @@ -1934,14 +1940,7 @@ void DepsgraphRelationBuilder::build_object_data_geometry(Object *object) } } /* Materials. */ - if (object->totcol) { - for (int a = 1; a <= object->totcol; a++) { - Material *ma = give_current_material(object, a); - if (ma != NULL) { - build_material(ma); - } - } - } + build_materials(object->mat, object->totcol); /* Geometry collision. */ if (ELEM(object->type, OB_MESH, OB_CURVE, OB_LATTICE)) { // add geometry collider relations @@ -2236,6 +2235,16 @@ void DepsgraphRelationBuilder::build_material(Material *material) } } +void DepsgraphRelationBuilder::build_materials(Material **materials, int num_materials) +{ + for (int i = 0; i < num_materials; ++i) { + if (materials[i] == NULL) { + continue; + } + build_material(materials[i]); + } +} + /* Recursively build graph for texture */ void DepsgraphRelationBuilder::build_texture(Tex *texture) { |