From 24e7db8f43a35a50887400f8256b69117f32e6a8 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev <117672381+akleshchev@users.noreply.github.com> Date: Tue, 25 Aug 2026 20:39:11 +0300 Subject: #6194 Tighten exception handling for mikk::Mikktspace --- indra/llmath/llvolume.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'indra/llmath/llvolume.cpp') diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index ece52db1b1..09a0ce0b7a 100644 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -58,6 +58,10 @@ #include "meshoptimizer/meshoptimizer.h" +#if LL_WINDOWS +#include //SEH +#endif + #define DEBUG_SILHOUETTE_BINORMALS 0 #define DEBUG_SILHOUETTE_NORMALS 0 // TomY: Use this to display normals using the silhouette #define DEBUG_SILHOUETTE_EDGE_MAP 0 // DaveP: Use this to display edge map using the silhouette @@ -5963,6 +5967,28 @@ struct MikktData } }; +#if LL_WINDOWS +static void genTangSpaceCPP(mikk::Mikktspace& ctx) +{ + ctx.genTangSpace(); +} +static bool genTangSpaceSEH(mikk::Mikktspace& ctx) +{ + __try + { + genTangSpaceCPP(ctx); + return true; + } + __except (msc_exception_filter(GetExceptionCode(), GetExceptionInformation())) + { + // Likely low memory or bad input; abort tangent generation for this + // mesh and let the caller decide how to proceed. + // (C++ exceptions like std::bad_alloc are not handled here) + return false; + } +} +#endif + bool LLVolumeFace::cacheOptimize(bool gen_tangents) { //optimize for vertex cache according to Forsyth method: LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME; @@ -6008,9 +6034,19 @@ bool LLVolumeFace::cacheOptimize(bool gen_tangents) // and is executed on a background thread MikktData data(this); mikk::Mikktspace ctx(data); + bool tangent_ok = false; try { +#if LL_WINDOWS + tangent_ok = genTangSpaceSEH(ctx); + if (!tangent_ok) + { + LL_WARNS_ONCE("LLVolume") << "SEH exception in Mikktspace::genTangSpace()" << LL_ENDL; + } +#else ctx.genTangSpace(); + tangent_ok = true; +#endif } catch (std::bad_alloc&) { @@ -6020,6 +6056,10 @@ bool LLVolumeFace::cacheOptimize(bool gen_tangents) catch (...) { LL_WARNS_ONCE("LLVolume") << "Mikktspace::genTangSpace() failed" << LL_ENDL; + } + + if (!tangent_ok) + { return false; } -- cgit v1.3