mirror of
https://github.com/isledecomp/isle-portable.git
synced 2025-09-24 04:26:55 -04:00
Fix UB in software renderer (#322)
* Fix UB in software renderer One cannot access elements of the vector that don't exist. `reserve` allocates memory, but doesn't add elements. `D3DRMVERTEX& dst = m_transformedVerts[i];` is UB and crashes on Windows debug build * Update renderer.cpp
This commit is contained in:
parent
0cfcc0fb21
commit
83205e2e4e
@ -710,10 +710,9 @@ void Direct3DRMSoftwareRenderer::SubmitDraw(
|
|||||||
|
|
||||||
// Pre-transform all vertex positions and normals
|
// Pre-transform all vertex positions and normals
|
||||||
m_transformedVerts.clear();
|
m_transformedVerts.clear();
|
||||||
m_transformedVerts.reserve(mesh.vertices.size());
|
m_transformedVerts.resize(mesh.vertices.size());
|
||||||
for (size_t i = 0; i < mesh.vertices.size(); ++i) {
|
for (const auto& src : mesh.vertices) {
|
||||||
const D3DRMVERTEX& src = mesh.vertices[i];
|
D3DRMVERTEX& dst = m_transformedVerts.emplace_back();
|
||||||
D3DRMVERTEX& dst = m_transformedVerts[i];
|
|
||||||
dst.position = TransformPoint(src.position, modelViewMatrix);
|
dst.position = TransformPoint(src.position, modelViewMatrix);
|
||||||
dst.normal = src.normal;
|
dst.normal = src.normal;
|
||||||
dst.texCoord = src.texCoord;
|
dst.texCoord = src.texCoord;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user