mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Fix CMeshBuffer::append reallocating too eagerly (#14969)
This commit is contained in:
parent
53c2fbb4c4
commit
a6f1242a11
1 changed files with 10 additions and 5 deletions
|
@ -170,16 +170,21 @@ public:
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const u32 vertexCount = getVertexCount();
|
const u32 vertexCount = getVertexCount();
|
||||||
u32 i;
|
|
||||||
|
|
||||||
Vertices.reallocate(vertexCount + numVertices);
|
// Only reallocate if there are enough new vertices. Otherwise append()
|
||||||
for (i = 0; i < numVertices; ++i) {
|
// will be slow when called in a loop.
|
||||||
|
if (vertexCount + numVertices > Vertices.allocated_size() * 3 / 2)
|
||||||
|
Vertices.reallocate(vertexCount + numVertices);
|
||||||
|
|
||||||
|
for (u32 i = 0; i < numVertices; ++i) {
|
||||||
Vertices.push_back(static_cast<const T *>(vertices)[i]);
|
Vertices.push_back(static_cast<const T *>(vertices)[i]);
|
||||||
BoundingBox.addInternalPoint(static_cast<const T *>(vertices)[i].Pos);
|
BoundingBox.addInternalPoint(static_cast<const T *>(vertices)[i].Pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
Indices.reallocate(getIndexCount() + numIndices);
|
if (getIndexCount() + numIndices > Indices.allocated_size() * 3 / 2)
|
||||||
for (i = 0; i < numIndices; ++i) {
|
Indices.reallocate(getIndexCount() + numIndices);
|
||||||
|
|
||||||
|
for (u32 i = 0; i < numIndices; ++i) {
|
||||||
Indices.push_back(indices[i] + vertexCount);
|
Indices.push_back(indices[i] + vertexCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue