Skip to content

Commit 563c35e

Browse files
committed
Issue#894 Crash at load3 in cacheOptimize
1 parent ae7b318 commit 563c35e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

indra/llmath/llvolume.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5592,9 +5592,9 @@ bool LLVolumeFace::cacheOptimize(bool gen_tangents)
55925592

55935593
U32 stream_count = data.w.empty() ? 4 : 5;
55945594

5595-
U32 vert_count = meshopt_generateVertexRemapMulti(&remap[0], nullptr, data.p.size(), data.p.size(), mos, stream_count);
5595+
size_t vert_count = meshopt_generateVertexRemapMulti(&remap[0], nullptr, data.p.size(), data.p.size(), mos, stream_count);
55965596

5597-
if (vert_count < 65535)
5597+
if (vert_count < 65535 && vert_count != 0)
55985598
{
55995599
std::vector<U32> indices;
56005600
indices.resize(mNumIndices);
@@ -5613,6 +5613,13 @@ bool LLVolumeFace::cacheOptimize(bool gen_tangents)
56135613
{
56145614
U32 src_idx = i;
56155615
U32 dst_idx = remap[i];
5616+
if (dst_idx >= mNumVertices)
5617+
{
5618+
dst_idx = mNumVertices - 1;
5619+
// Shouldn't happen, figure out what gets returned in remap and why.
5620+
llassert(false);
5621+
LL_DEBUGS_ONCE("LLVOLUME") << "Invalid destination index, substituting" << LL_ENDL;
5622+
}
56165623
mIndices[i] = dst_idx;
56175624

56185625
mPositions[dst_idx].load3(data.p[src_idx].mV);
@@ -5646,6 +5653,10 @@ bool LLVolumeFace::cacheOptimize(bool gen_tangents)
56465653
}
56475654
else
56485655
{
5656+
if (vert_count == 0)
5657+
{
5658+
LL_WARNS_ONCE("LLVOLUME") << "meshopt_generateVertexRemapMulti failed to process a model or model was invalid" << LL_ENDL;
5659+
}
56495660
// blew past the max vertex size limit, use legacy tangent generation which never adds verts
56505661
createTangents();
56515662
}

0 commit comments

Comments
 (0)