Effectively ensure that surface materials are the right size when setting them, fixes #23596

This commit is contained in:
Juan Linietsky 2018-11-08 15:58:52 -03:00
parent d403b4086c
commit 555fb3a317
2 changed files with 6 additions and 2 deletions

View file

@ -102,6 +102,9 @@ void PrimitiveMesh::_request_update() {
} }
int PrimitiveMesh::get_surface_count() const { int PrimitiveMesh::get_surface_count() const {
if (pending_request) {
_update();
}
return 1; return 1;
} }

View file

@ -601,8 +601,9 @@ void VisualServerScene::instance_set_surface_material(RID p_instance, int p_surf
Instance *instance = instance_owner.get(p_instance); Instance *instance = instance_owner.get(p_instance);
ERR_FAIL_COND(!instance); ERR_FAIL_COND(!instance);
if (instance->update_item.in_list()) { if (instance->base_type == VS::INSTANCE_MESH) {
_update_dirty_instance(instance); //may not have been updated yet
instance->materials.resize(VSG::storage->mesh_get_surface_count(instance->base));
} }
ERR_FAIL_INDEX(p_surface, instance->materials.size()); ERR_FAIL_INDEX(p_surface, instance->materials.size());