A typical daily bug to ponder from AAA code base "Redefining the next-generation of technology in games".
The cut down example implements Vector3 - inheriting 4 elements from base, sets 3 elements and asserts calling base::Validation() because the 4th element is never set.
Note.
1. Clearly no use of debug build during development.
2. Unnecessary code in core code.
const unsigned int NAN = 0x7FC00000;
bool ValidateElement( unsigned int value )
{
return value == NAN ? false : true;
}
class VectorBase
{
private:
float m_x;
float m_y;
float m_z;
float m_w;
public:
VectorBase()
{
*((unsigned int *) &m_x) = NAN ;
*((unsigned int *) &m_y) = NAN ;
*((unsigned int *) &m_z) = NAN ;
*((unsigned int *) &m_w) = NAN ;
}
float GetX() { return m_x; }
float GetY() { return m_y; }
float GetZ() { return m_z; }
float GetW() { return m_w; }
bool Validate()
{
return ValidateElement( GetX() ) &&
ValidateElement( GetY() ) &&
ValidateElement( GetZ() ) &&
ValidateElement( GetW() );
}
}
class Vector3 : public VectorBase
{
public:
Vector3() {}
void Set( float x, float y, float z)
{
m_x = x;
m_y = x;
m_z = x;
}
float GetX() { return m_x; }
float GetY() { return m_y; }
float GetZ() { return m_z; }
float GetW() { return 0.f; }
}
int main(int argCount, char*argStr[])
{
Vector3 v3;
v3.Set (0.f, 0.f, 0.f);
ASSERT( v3.Validate () );
return 0;
}