Added safety range-check to VertexMapper methods

Former-commit-id: 63424008656619b44237f640b2f2bc7a67d70040
This commit is contained in:
Lynix 2013-05-11 19:08:38 +02:00
parent b69963e93f
commit 4d9ba84d03
1 changed files with 58 additions and 1 deletions

View File

@ -45,7 +45,8 @@ NzVector3f NzVertexMapper::GetNormal(unsigned int i) const
#if NAZARA_UTILITY_SAFE #if NAZARA_UTILITY_SAFE
if (i >= m_vertexCount) if (i >= m_vertexCount)
{ {
NazaraError("Vertex index out of range (" + NzString::Number(i) + " >= " + NzString::Number(m_vertexCount) + ')');
return NzVector3f();
} }
#endif #endif
@ -54,16 +55,40 @@ NzVector3f NzVertexMapper::GetNormal(unsigned int i) const
NzVector3f NzVertexMapper::GetPosition(unsigned int i) const NzVector3f NzVertexMapper::GetPosition(unsigned int i) const
{ {
#if NAZARA_UTILITY_SAFE
if (i >= m_vertexCount)
{
NazaraError("Vertex index out of range (" + NzString::Number(i) + " >= " + NzString::Number(m_vertexCount) + ')');
return NzVector3f();
}
#endif
return m_vertices[i].position; return m_vertices[i].position;
} }
NzVector3f NzVertexMapper::GetTangent(unsigned int i) const NzVector3f NzVertexMapper::GetTangent(unsigned int i) const
{ {
#if NAZARA_UTILITY_SAFE
if (i >= m_vertexCount)
{
NazaraError("Vertex index out of range (" + NzString::Number(i) + " >= " + NzString::Number(m_vertexCount) + ')');
return NzVector3f();
}
#endif
return m_vertices[i].tangent; return m_vertices[i].tangent;
} }
NzVector2f NzVertexMapper::GetTexCoord(unsigned int i) const NzVector2f NzVertexMapper::GetTexCoord(unsigned int i) const
{ {
#if NAZARA_UTILITY_SAFE
if (i >= m_vertexCount)
{
NazaraError("Vertex index out of range (" + NzString::Number(i) + " >= " + NzString::Number(m_vertexCount) + ')');
return NzVector2f();
}
#endif
return m_vertices[i].uv; return m_vertices[i].uv;
} }
@ -74,21 +99,53 @@ unsigned int NzVertexMapper::GetVertexCount()
void NzVertexMapper::SetNormal(unsigned int i, const NzVector3f& normal) void NzVertexMapper::SetNormal(unsigned int i, const NzVector3f& normal)
{ {
#if NAZARA_UTILITY_SAFE
if (i >= m_vertexCount)
{
NazaraError("Vertex index out of range (" + NzString::Number(i) + " >= " + NzString::Number(m_vertexCount) + ')');
return;
}
#endif
m_vertices[i].normal = normal; m_vertices[i].normal = normal;
} }
void NzVertexMapper::SetPosition(unsigned int i, const NzVector3f& position) void NzVertexMapper::SetPosition(unsigned int i, const NzVector3f& position)
{ {
#if NAZARA_UTILITY_SAFE
if (i >= m_vertexCount)
{
NazaraError("Vertex index out of range (" + NzString::Number(i) + " >= " + NzString::Number(m_vertexCount) + ')');
return;
}
#endif
m_vertices[i].position = position; m_vertices[i].position = position;
} }
void NzVertexMapper::SetTangent(unsigned int i, const NzVector3f& tangent) void NzVertexMapper::SetTangent(unsigned int i, const NzVector3f& tangent)
{ {
#if NAZARA_UTILITY_SAFE
if (i >= m_vertexCount)
{
NazaraError("Vertex index out of range (" + NzString::Number(i) + " >= " + NzString::Number(m_vertexCount) + ')');
return;
}
#endif
m_vertices[i].tangent = tangent; m_vertices[i].tangent = tangent;
} }
void NzVertexMapper::SetTexCoord(unsigned int i, const NzVector2f& texCoord) void NzVertexMapper::SetTexCoord(unsigned int i, const NzVector2f& texCoord)
{ {
#if NAZARA_UTILITY_SAFE
if (i >= m_vertexCount)
{
NazaraError("Vertex index out of range (" + NzString::Number(i) + " >= " + NzString::Number(m_vertexCount) + ')');
return;
}
#endif
m_vertices[i].uv = texCoord; m_vertices[i].uv = texCoord;
} }