From d36eff4ed33590f9c799057b784a9f70c31dedea Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 5 Apr 2020 02:08:08 +0200 Subject: [PATCH] Fix potential crash. --- world/voxel_chunk_default.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/world/voxel_chunk_default.cpp b/world/voxel_chunk_default.cpp index 3c98667..630e16b 100644 --- a/world/voxel_chunk_default.cpp +++ b/world/voxel_chunk_default.cpp @@ -1124,15 +1124,24 @@ void VoxelChunkDefault::_build_phase(int phase) { if (_lod_num >= 3) { Ref mat = get_library()->get_material(0); - Ref tex = mat->get_shader_param("texture_albedo"); + Ref spmat = get_library()->get_material(0); + Ref tex; - temp_mesh_arr = bake_mesh_array_uv(temp_mesh_arr, tex); - temp_mesh_arr[VisualServer::ARRAY_TEX_UV] = Variant(); + if (mat.is_valid()) { + tex = mat->get_shader_param("texture_albedo"); + } else if (spmat.is_valid()) { + tex = spmat->get_texture(SpatialMaterial::TEXTURE_ALBEDO); + } - VisualServer::get_singleton()->mesh_add_surface_from_arrays(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 3), VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr); + if (tex.is_valid()) { + temp_mesh_arr = bake_mesh_array_uv(temp_mesh_arr, tex); + temp_mesh_arr[VisualServer::ARRAY_TEX_UV] = Variant(); - if (get_library()->get_material(3).is_valid()) - VisualServer::get_singleton()->mesh_surface_set_material(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 3), 0, get_library()->get_material(3)->get_rid()); + VisualServer::get_singleton()->mesh_add_surface_from_arrays(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 3), VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr); + + if (get_library()->get_material(3).is_valid()) + VisualServer::get_singleton()->mesh_surface_set_material(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 3), 0, get_library()->get_material(3)->get_rid()); + } } /*