From 0959ff2fe4e50ad29866ae1f3fba3133fce152b3 Mon Sep 17 00:00:00 2001 From: jfons Date: Thu, 24 Feb 2022 13:00:51 +0100 Subject: [PATCH] Add sanity checks to lightmap unwrap texel size (cherry picked from commit d0fd5fd3c787210fa584e4a933280bd82daaec02) --- modules/xatlas_unwrap/register_types.cpp | 2 ++ scene/resources/mesh.cpp | 1 + 2 files changed, 3 insertions(+) diff --git a/modules/xatlas_unwrap/register_types.cpp b/modules/xatlas_unwrap/register_types.cpp index bb3bf8b4c74..fdf2241c117 100644 --- a/modules/xatlas_unwrap/register_types.cpp +++ b/modules/xatlas_unwrap/register_types.cpp @@ -57,6 +57,8 @@ bool xatlas_mesh_lightmap_unwrap_callback(float p_texel_size, const float *p_ver xatlas::ChartOptions chart_options; chart_options.fixWinding = true; + ERR_FAIL_COND_V_MSG(p_texel_size <= 0.0f, false, "Texel size must be greater than 0."); + xatlas::PackOptions pack_options; pack_options.padding = 1; pack_options.maxChartSize = 4094; // Lightmap atlassing needs 2 for padding between meshes, so 4096-2 diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index 65ccfc9ef18..0edc6c05eb3 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -1063,6 +1063,7 @@ Error ArrayMesh::lightmap_unwrap(const Transform &p_base_transform, float p_texe Error ArrayMesh::lightmap_unwrap_cached(int *&r_cache_data, unsigned int &r_cache_size, bool &r_used_cache, const Transform &p_base_transform, float p_texel_size) { ERR_FAIL_COND_V(!array_mesh_lightmap_unwrap_callback, ERR_UNCONFIGURED); ERR_FAIL_COND_V_MSG(blend_shapes.size() != 0, ERR_UNAVAILABLE, "Can't unwrap mesh with blend shapes."); + ERR_FAIL_COND_V_MSG(p_texel_size <= 0.0f, ERR_PARAMETER_RANGE_ERROR, "Texel size must be greater than 0."); LocalVector vertices; LocalVector normals;