Fixed possible buffer overflow.

This commit is contained in:
Leonardo Zide 2020-01-24 13:12:34 -08:00
parent 3b8b22493a
commit 93e8f4a85e

View file

@ -1421,6 +1421,7 @@ void lcPiecesLibrary::UpdateBuffers(lcContext* Context)
int VertexDataSize = 0;
int IndexDataSize = 0;
std::vector<lcMesh*> Meshes;
for (const auto& PieceIt : mPieces)
{
@ -1435,6 +1436,8 @@ void lcPiecesLibrary::UpdateBuffers(lcContext* Context)
VertexDataSize += Mesh->mVertexDataSize;
IndexDataSize += Mesh->mIndexDataSize;
Meshes.push_back(Mesh);
}
Context->DestroyVertexBuffer(mVertexBuffer);
@ -1449,17 +1452,8 @@ void lcPiecesLibrary::UpdateBuffers(lcContext* Context)
VertexDataSize = 0;
IndexDataSize = 0;
for (const auto& PieceIt : mPieces)
for (lcMesh* Mesh : Meshes)
{
PieceInfo* Info = PieceIt.second;
lcMesh* Mesh = Info->IsPlaceholder() ? gPlaceholderMesh : Info->GetMesh();
if (!Mesh)
continue;
if (Mesh->mVertexDataSize > 16 * 1024 * 1024 || Mesh->mIndexDataSize > 16 * 1024 * 1024)
continue;
Mesh->mVertexCacheOffset = VertexDataSize;
Mesh->mIndexCacheOffset = IndexDataSize;