More replacing assert() with POLYVOX_ASSERT.

This commit is contained in:
David Williams 2013-01-01 14:50:58 +00:00
parent 4fcc8a15d7
commit 29720c4568
7 changed files with 33 additions and 32 deletions

View File

@ -38,14 +38,14 @@ namespace PolyVox
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// This function should never be called. Copying volumes by value would be expensive, and we want to prevent users from doing /// This function should never be called. Copying volumes by value would be expensive, and we want to prevent users from doing
/// it by accident (such as when passing them as paramenters to functions). That said, there are times when you really do want to /// it by accident (such as when passing them as paramenters to functions). That said, there are times when you really do want to
/// make a copy of a volume and in this case you should look at the Volumeresampler. /// make a copy of a volume and in this case you should look at the VolumeResampler.
/// ///
/// \sa VolumeResampler /// \sa VolumeResampler
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType> template <typename VoxelType>
BaseVolume<VoxelType>::BaseVolume(const BaseVolume<VoxelType>& /*rhs*/) BaseVolume<VoxelType>::BaseVolume(const BaseVolume<VoxelType>& /*rhs*/)
{ {
assert(false); // See function comment above. POLYVOX_ASSERT(false, "Copy constructor not implemented."); // See function comment above.
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -66,7 +66,7 @@ namespace PolyVox
template <typename VoxelType> template <typename VoxelType>
BaseVolume<VoxelType>& BaseVolume<VoxelType>::operator=(const BaseVolume<VoxelType>& /*rhs*/) BaseVolume<VoxelType>& BaseVolume<VoxelType>::operator=(const BaseVolume<VoxelType>& /*rhs*/)
{ {
assert(false); // See function comment above. POLYVOX_ASSERT(false, "Assignment operator not implemented."); // See function comment above.
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -162,7 +162,7 @@ namespace PolyVox
template <typename VoxelType> template <typename VoxelType>
VoxelType BaseVolume<VoxelType>::getVoxel(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/) const VoxelType BaseVolume<VoxelType>::getVoxel(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/) const
{ {
assert(false); POLYVOX_ASSERT(false, "You should never call the base class version of this function.");
return VoxelType(); return VoxelType();
} }
@ -173,7 +173,7 @@ namespace PolyVox
template <typename VoxelType> template <typename VoxelType>
VoxelType BaseVolume<VoxelType>::getVoxel(const Vector3DInt32& /*v3dPos*/) const VoxelType BaseVolume<VoxelType>::getVoxel(const Vector3DInt32& /*v3dPos*/) const
{ {
assert(false); POLYVOX_ASSERT(false, "You should never call the base class version of this function.");
return VoxelType(); return VoxelType();
} }
@ -186,7 +186,7 @@ namespace PolyVox
template <typename VoxelType> template <typename VoxelType>
VoxelType BaseVolume<VoxelType>::getVoxelAt(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/) const VoxelType BaseVolume<VoxelType>::getVoxelAt(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/) const
{ {
assert(false); POLYVOX_ASSERT(false, "You should never call the base class version of this function.");
return VoxelType(); return VoxelType();
} }
@ -197,7 +197,7 @@ namespace PolyVox
template <typename VoxelType> template <typename VoxelType>
VoxelType BaseVolume<VoxelType>::getVoxelAt(const Vector3DInt32& /*v3dPos*/) const VoxelType BaseVolume<VoxelType>::getVoxelAt(const Vector3DInt32& /*v3dPos*/) const
{ {
assert(false); POLYVOX_ASSERT(false, "You should never call the base class version of this function.");
return VoxelType(); return VoxelType();
} }
@ -210,7 +210,7 @@ namespace PolyVox
template <typename VoxelType> template <typename VoxelType>
VoxelType BaseVolume<VoxelType>::getVoxelWithWrapping(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, WrapMode /*eWrapMode*/, VoxelType /*tBorder*/) const VoxelType BaseVolume<VoxelType>::getVoxelWithWrapping(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, WrapMode /*eWrapMode*/, VoxelType /*tBorder*/) const
{ {
assert(false); POLYVOX_ASSERT(false, "You should never call the base class version of this function.");
return VoxelType(); return VoxelType();
} }
@ -221,7 +221,7 @@ namespace PolyVox
template <typename VoxelType> template <typename VoxelType>
VoxelType BaseVolume<VoxelType>::getVoxelWithWrapping(const Vector3DInt32& /*v3dPos*/, WrapMode /*eWrapMode*/, VoxelType /*tBorder*/) const VoxelType BaseVolume<VoxelType>::getVoxelWithWrapping(const Vector3DInt32& /*v3dPos*/, WrapMode /*eWrapMode*/, VoxelType /*tBorder*/) const
{ {
assert(false); POLYVOX_ASSERT(false, "You should never call the base class version of this function.");
return VoxelType(); return VoxelType();
} }
@ -244,7 +244,7 @@ namespace PolyVox
template <typename VoxelType> template <typename VoxelType>
bool BaseVolume<VoxelType>::setVoxelAt(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, VoxelType /*tValue*/) bool BaseVolume<VoxelType>::setVoxelAt(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, VoxelType /*tValue*/)
{ {
assert(false); POLYVOX_ASSERT(false, "You should never call the base class version of this function.");
return false; return false;
} }
@ -256,7 +256,7 @@ namespace PolyVox
template <typename VoxelType> template <typename VoxelType>
bool BaseVolume<VoxelType>::setVoxelAt(const Vector3DInt32& /*v3dPos*/, VoxelType /*tValue*/) bool BaseVolume<VoxelType>::setVoxelAt(const Vector3DInt32& /*v3dPos*/, VoxelType /*tValue*/)
{ {
assert(false); POLYVOX_ASSERT(false, "You should never call the base class version of this function.");
return false; return false;
} }

View File

@ -375,7 +375,7 @@ namespace PolyVox
default: default:
{ {
//Should never happen //Should never happen
assert(false); POLYVOX_ASSERT(false, "Invalid case.");
return VoxelType(0); return VoxelType(0);
} }
} }

View File

@ -37,25 +37,25 @@ namespace PolyVox
public: public:
VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const
{ {
assert(m_regValid.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos))); POLYVOX_ASSERT(m_regValid.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)), "Position is outside valid region");
return m_pVolume.getVoxelAt(uXPos, uYPos, uZPos); return m_pVolume.getVoxelAt(uXPos, uYPos, uZPos);
} }
VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const
{ {
assert(m_regValid.containsPoint(v3dPos)); POLYVOX_ASSERT(m_regValid.containsPoint(v3dPos), "Position is outside valid region");
return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
} }
void setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) const void setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) const
{ {
assert(m_regValid.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos))); POLYVOX_ASSERT(m_regValid.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)), "Position is outside valid region");
m_pVolume.setVoxelAtConst(uXPos, uYPos, uZPos, tValue); m_pVolume.setVoxelAtConst(uXPos, uYPos, uZPos, tValue);
} }
void setVoxelAt(const Vector3DInt32& v3dPos, VoxelType tValue) const void setVoxelAt(const Vector3DInt32& v3dPos, VoxelType tValue) const
{ {
assert(m_regValid.containsPoint(v3dPos)); POLYVOX_ASSERT(m_regValid.containsPoint(v3dPos), "Position is outside valid region");
setVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue); setVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue);
} }
private: private:

View File

@ -224,7 +224,7 @@ namespace PolyVox
// If we exit the loop here then apparently all the slots were full but none of them matched. I don't think // If we exit the loop here then apparently all the slots were full but none of them matched. I don't think
// this can happen so let's put an assert to make sure. If you hit this assert then please report it to us! // this can happen so let's put an assert to make sure. If you hit this assert then please report it to us!
assert(false); POLYVOX_ASSERT(false, "All slots full but no matches.");
return -1; //Should never happen. return -1; //Should never happen.
} }

View File

@ -33,7 +33,7 @@ namespace PolyVox
const Type& v0,const Type& v1, const Type& v0,const Type& v1,
const float x) const float x)
{ {
assert((x >= 0.0f) && (x <= 1.0f)); POLYVOX_ASSERT((x >= 0.0f) && (x <= 1.0f), "Interpolation input out of 0.0 to 1.0 range.");
//Interpolate along X //Interpolate along X
Type v0_1 = (v1 - v0) * x + v0; Type v0_1 = (v1 - v0) * x + v0;
@ -46,8 +46,8 @@ namespace PolyVox
const Type& v00,const Type& v10,const Type& v01,const Type& v11, const Type& v00,const Type& v10,const Type& v01,const Type& v11,
const float x, const float y) const float x, const float y)
{ {
assert((x >= 0.0f) && (y >= 0.0f) && POLYVOX_ASSERT((x >= 0.0f) && (y >= 0.0f) &&
(x <= 1.0f) && (y <= 1.0f)); (x <= 1.0f) && (y <= 1.0f), "Interpolation input out of 0.0 to 1.0 range.");
// Linearly interpolate along x // Linearly interpolate along x
Type v00_10 = lerp(v00, v10, x); Type v00_10 = lerp(v00, v10, x);
@ -65,8 +65,8 @@ namespace PolyVox
const Type& v001,const Type& v101,const Type& v011,const Type& v111, const Type& v001,const Type& v101,const Type& v011,const Type& v111,
const float x, const float y, const float z) const float x, const float y, const float z)
{ {
assert((x >= 0.0f) && (y >= 0.0f) && (z >= 0.0f) && POLYVOX_ASSERT((x >= 0.0f) && (y >= 0.0f) && (z >= 0.0f) &&
(x <= 1.0f) && (y <= 1.0f) && (z <= 1.0f)); (x <= 1.0f) && (y <= 1.0f) && (z <= 1.0f), "Interpolation input out of 0.0 to 1.0 range.");
// Bilinearly interpolate along Y // Bilinearly interpolate along Y
Type v000_v100__v010_v110 = bilerp(v000, v100, v010, v110, x, y); Type v000_v100__v010_v110 = bilerp(v000, v100, v010, v110, x, y);

View File

@ -87,7 +87,7 @@ namespace PolyVox
template <typename VoxelType> template <typename VoxelType>
LargeVolume<VoxelType>::LargeVolume(const LargeVolume<VoxelType>& /*rhs*/) LargeVolume<VoxelType>::LargeVolume(const LargeVolume<VoxelType>& /*rhs*/)
{ {
assert(false); // See function comment above. POLYVOX_ASSERT(false, "Copy constructor not implemented."); // See function comment above.
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -109,7 +109,7 @@ namespace PolyVox
template <typename VoxelType> template <typename VoxelType>
LargeVolume<VoxelType>& LargeVolume<VoxelType>::operator=(const LargeVolume<VoxelType>& /*rhs*/) LargeVolume<VoxelType>& LargeVolume<VoxelType>::operator=(const LargeVolume<VoxelType>& /*rhs*/)
{ {
assert(false); // See function comment above. POLYVOX_ASSERT(false, "Assignment operator not implemented."); // See function comment above.
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -121,7 +121,7 @@ namespace PolyVox
template <typename VoxelType> template <typename VoxelType>
VoxelType LargeVolume<VoxelType>::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const VoxelType LargeVolume<VoxelType>::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const
{ {
assert(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos))); POLYVOX_ASSERT(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)), "Position is outside valid region");
const int32_t blockX = uXPos >> m_uBlockSideLengthPower; const int32_t blockX = uXPos >> m_uBlockSideLengthPower;
const int32_t blockY = uYPos >> m_uBlockSideLengthPower; const int32_t blockY = uYPos >> m_uBlockSideLengthPower;
@ -225,7 +225,7 @@ namespace PolyVox
default: default:
{ {
//Should never happen //Should never happen
assert(false); POLYVOX_ASSERT(false, "Invlaid case.");
return VoxelType(0); return VoxelType(0);
} }
} }
@ -303,7 +303,7 @@ namespace PolyVox
template <typename VoxelType> template <typename VoxelType>
bool LargeVolume<VoxelType>::setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) bool LargeVolume<VoxelType>::setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue)
{ {
assert(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos))); POLYVOX_ASSERT(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)), "Position is outside valid region");
const int32_t blockX = uXPos >> m_uBlockSideLengthPower; const int32_t blockX = uXPos >> m_uBlockSideLengthPower;
const int32_t blockY = uYPos >> m_uBlockSideLengthPower; const int32_t blockY = uYPos >> m_uBlockSideLengthPower;
@ -468,7 +468,8 @@ namespace PolyVox
void LargeVolume<VoxelType>::initialise(const Region& regValidRegion, uint16_t uBlockSideLength) void LargeVolume<VoxelType>::initialise(const Region& regValidRegion, uint16_t uBlockSideLength)
{ {
//Debug mode validation //Debug mode validation
assert(uBlockSideLength > 0); POLYVOX_ASSERT(uBlockSideLength > 0, "Block side length cannot be zero.");
POLYVOX_ASSERT(isPowerOf2(uBlockSideLength), "Block side length must be a power of two.");
//Release mode validation //Release mode validation
if(uBlockSideLength == 0) if(uBlockSideLength == 0)
@ -583,7 +584,7 @@ namespace PolyVox
//This check should also provide a significant speed boost as usually it is true. //This check should also provide a significant speed boost as usually it is true.
if((v3dBlockPos == m_v3dLastAccessedBlockPos) && (m_pLastAccessedBlock != 0)) if((v3dBlockPos == m_v3dLastAccessedBlockPos) && (m_pLastAccessedBlock != 0))
{ {
assert(m_pLastAccessedBlock->m_tUncompressedData); POLYVOX_ASSERT(m_pLastAccessedBlock->m_tUncompressedData, "Block has no uncompressed data");
return m_pLastAccessedBlock; return m_pLastAccessedBlock;
} }
@ -643,7 +644,7 @@ namespace PolyVox
if(loadedBlock.block.m_bIsCompressed == false) if(loadedBlock.block.m_bIsCompressed == false)
{ {
assert(m_pLastAccessedBlock->m_tUncompressedData); POLYVOX_ASSERT(m_pLastAccessedBlock->m_tUncompressedData, "Block has no uncompressed data");
return m_pLastAccessedBlock; return m_pLastAccessedBlock;
} }
@ -680,7 +681,7 @@ namespace PolyVox
loadedBlock.block.uncompress(); loadedBlock.block.uncompress();
m_pLastAccessedBlock = &(loadedBlock.block); m_pLastAccessedBlock = &(loadedBlock.block);
assert(m_pLastAccessedBlock->m_tUncompressedData); POLYVOX_ASSERT(m_pLastAccessedBlock->m_tUncompressedData, "Block has no uncompressed data");
return m_pLastAccessedBlock; return m_pLastAccessedBlock;
} }

View File

@ -143,7 +143,7 @@ namespace PolyVox
}*/ }*/
//Need to think what effect this has on any existing iterators. //Need to think what effect this has on any existing iterators.
assert(false); POLYVOX_ASSERT(false, "This function cnnot be used on LargeVolume samplers.");
return false; return false;
} }