Fixed divide by zero in Shape.cpp (#499)

This commit is contained in:
Laurent Gomila 2013-11-30 20:57:18 +01:00
parent ef1d29bf73
commit de3ea71631

View File

@ -240,8 +240,8 @@ void Shape::updateTexCoords()
{ {
for (unsigned int i = 0; i < m_vertices.getVertexCount(); ++i) for (unsigned int i = 0; i < m_vertices.getVertexCount(); ++i)
{ {
float xratio = (m_vertices[i].position.x - m_insideBounds.left) / m_insideBounds.width; float xratio = m_insideBounds.width > 0 ? (m_vertices[i].position.x - m_insideBounds.left) / m_insideBounds.width : 0;
float yratio = (m_vertices[i].position.y - m_insideBounds.top) / m_insideBounds.height; float yratio = m_insideBounds.height > 0 ? (m_vertices[i].position.y - m_insideBounds.top) / m_insideBounds.height : 0;
m_vertices[i].texCoords.x = m_textureRect.left + m_textureRect.width * xratio; m_vertices[i].texCoords.x = m_textureRect.left + m_textureRect.width * xratio;
m_vertices[i].texCoords.y = m_textureRect.top + m_textureRect.height * yratio; m_vertices[i].texCoords.y = m_textureRect.top + m_textureRect.height * yratio;
} }