From 858a9c0e1b8bf7da747a01b44f0f7d319800087f Mon Sep 17 00:00:00 2001 From: David Williams Date: Tue, 1 Jan 2013 14:09:40 +0000 Subject: [PATCH] Replaced some assert()s with POLYVOX_ASSERT()s. --- .../include/PolyVoxCore/AStarPathfinder.inl | 10 ++++--- .../AmbientOcclusionCalculator.inl | 8 ++--- .../PolyVoxCore/include/PolyVoxCore/Array.inl | 20 ++++++------- .../include/PolyVoxCore/Impl/Block.inl | 29 ++++++++++--------- .../include/PolyVoxCore/Impl/SubArray.inl | 10 +++---- 5 files changed, 40 insertions(+), 37 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.inl b/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.inl index 26c5c398..c8fce4fb 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.inl @@ -21,6 +21,8 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ +#include "PolyVoxCore/Impl/ErrorHandling.h" + namespace PolyVox { //////////////////////////////////////////////////////////////////////////////// @@ -296,14 +298,14 @@ namespace PolyVox hVal = SixConnectedCost(a, b); break; default: - assert(false); //Invalid case. + POLYVOX_ASSERT(false, "Invalid case"); } //Sanity checks in debug mode. These can come out eventually, but I //want to make sure that the heuristics I've come up with make sense. - assert((a-b).length() <= TwentySixConnectedCost(a,b)); - assert(TwentySixConnectedCost(a,b) <= EighteenConnectedCost(a,b)); - assert(EighteenConnectedCost(a,b) <= SixConnectedCost(a,b)); + POLYVOX_ASSERT((a-b).length() <= TwentySixConnectedCost(a,b), "A* heuristic error."); + POLYVOX_ASSERT(TwentySixConnectedCost(a,b) <= EighteenConnectedCost(a,b), "A* heuristic error."); + POLYVOX_ASSERT(EighteenConnectedCost(a,b) <= SixConnectedCost(a,b), "A* heuristic error."); //Apply the bias to the computed h value; hVal *= m_params.hBias; diff --git a/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl b/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl index 1c3c9727..95c1410e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl @@ -39,9 +39,9 @@ namespace PolyVox uint16_t uIndexIncreament; //Make sure that the size of the volume is an exact multiple of the size of the array. - assert(volInput->getWidth() % arrayResult->getDimension(0) == 0); - assert(volInput->getHeight() % arrayResult->getDimension(1) == 0); - assert(volInput->getDepth() % arrayResult->getDimension(2) == 0); + POLYVOX_ASSERT(volInput->getWidth() % arrayResult->getDimension(0) == 0, "Volume width must be an exact multiple of array width."); + POLYVOX_ASSERT(volInput->getHeight() % arrayResult->getDimension(1) == 0, "Volume height must be an exact multiple of array height."); + POLYVOX_ASSERT(volInput->getDepth() % arrayResult->getDimension(2) == 0, "Volume depth must be an exact multiple of array depth."); //Our initial indices. It doesn't matter exactly what we set here, but the code below makes //sure they are different for different regions which helps reduce tiling patterns in the results. @@ -116,7 +116,7 @@ namespace PolyVox else { fVisibility = static_cast(uVisibleDirections) / static_cast(uNoOfSamplesPerOutputElement); - assert((fVisibility >= 0.0f) && (fVisibility <= 1.0f)); + POLYVOX_ASSERT((fVisibility >= 0.0f) && (fVisibility <= 1.0f), "Visibility value out of range."); } (*arrayResult)[z / iRatioZ][y / iRatioY][x / iRatioX] = static_cast(255.0f * fVisibility); diff --git a/library/PolyVoxCore/include/PolyVoxCore/Array.inl b/library/PolyVoxCore/include/PolyVoxCore/Array.inl index 39d59701..366180c7 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Array.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Array.inl @@ -73,7 +73,7 @@ namespace PolyVox template SubArray Array::operator[](uint32_t uIndex) { - assert(uIndex(&m_pElements[uIndex*m_pOffsets[0]], m_pDimensions+1, m_pOffsets+1); @@ -91,7 +91,7 @@ namespace PolyVox template const SubArray Array::operator[](uint32_t uIndex) const { - assert(uIndex(&m_pElements[uIndex*m_pOffsets[0]], m_pDimensions+1, m_pOffsets+1); @@ -139,7 +139,7 @@ namespace PolyVox m_uNoOfElements = 1; for (uint32_t i = 0; i uint32_t Array::getDimension(uint32_t uDimension) { - assert(uDimension < noOfDims); + POLYVOX_ASSERT(uDimension < noOfDims, "Dimension out of range"); return m_pDimensions[uDimension]; } @@ -198,14 +198,14 @@ namespace PolyVox ,m_uNoOfElements(0) { //Not implemented - assert(false); + POLYVOX_ASSERT(false, "Not implemented."); } template Array& Array::operator=(const Array& rhs) { //Not implemented - assert(false); + POLYVOX_ASSERT(false, "Not implemented."); return *this; } @@ -251,14 +251,14 @@ namespace PolyVox template ElementType& Array<1, ElementType>::operator[] (uint32_t uIndex) { - assert(uIndex const ElementType& Array<1, ElementType>::operator[] (uint32_t uIndex) const { - assert(uIndex Array<1, ElementType>& Array<1, ElementType>::operator=(const Array<1, ElementType>& rhs) { //Not implemented - assert(false); + POLYVOX_ASSERT(false, "Not implemented."); return *this; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl index 8927816c..226e7ded 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl @@ -24,7 +24,8 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Impl/Utility.h" #include "PolyVoxCore/Vector.h" -#include +#include "PolyVoxCore/Impl/ErrorHandling.h" + #include //For memcpy #include #include //for std::invalid_argument @@ -54,11 +55,11 @@ namespace PolyVox template VoxelType Block::getVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const { - assert(uXPos < m_uSideLength); - assert(uYPos < m_uSideLength); - assert(uZPos < m_uSideLength); + POLYVOX_ASSERT(uXPos < m_uSideLength, "Supplied position is outside of the block"); + POLYVOX_ASSERT(uYPos < m_uSideLength, "Supplied position is outside of the block"); + POLYVOX_ASSERT(uZPos < m_uSideLength, "Supplied position is outside of the block"); - assert(m_tUncompressedData); + POLYVOX_ASSERT(m_tUncompressedData, "No uncompressed data - block must be decompressed before accessing voxels."); return m_tUncompressedData [ @@ -77,11 +78,11 @@ namespace PolyVox template void Block::setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue) { - assert(uXPos < m_uSideLength); - assert(uYPos < m_uSideLength); - assert(uZPos < m_uSideLength); + POLYVOX_ASSERT(uXPos < m_uSideLength, "Supplied position is outside of the block"); + POLYVOX_ASSERT(uYPos < m_uSideLength, "Supplied position is outside of the block"); + POLYVOX_ASSERT(uZPos < m_uSideLength, "Supplied position is outside of the block"); - assert(m_tUncompressedData); + POLYVOX_ASSERT(m_tUncompressedData, "No uncompressed data - block must be decompressed before accessing voxels."); m_tUncompressedData [ @@ -125,7 +126,7 @@ namespace PolyVox void Block::initialise(uint16_t uSideLength) { //Debug mode validation - assert(isPowerOf2(uSideLength)); + POLYVOX_ASSERT(isPowerOf2(uSideLength), "Block side length must be a power of two."); //Release mode validation if(!isPowerOf2(uSideLength)) @@ -151,8 +152,8 @@ namespace PolyVox template void Block::compress(void) { - assert(m_bIsCompressed == false); - assert(m_tUncompressedData != 0); + POLYVOX_ASSERT(m_bIsCompressed == false, "Attempted to compress block which is already flagged as compressed."); + POLYVOX_ASSERT(m_tUncompressedData != 0, "No uncompressed data is present."); //If the uncompressed data hasn't actually been //modified then we don't need to redo the compression. @@ -197,8 +198,8 @@ namespace PolyVox template void Block::uncompress(void) { - assert(m_bIsCompressed == true); - assert(m_tUncompressedData == 0); + POLYVOX_ASSERT(m_bIsCompressed == true, "Attempted to uncompress block which is not flagged as compressed."); + POLYVOX_ASSERT(m_tUncompressedData == 0, "Uncompressed data already exists."); m_tUncompressedData = new VoxelType[m_uSideLength * m_uSideLength * m_uSideLength]; VoxelType* pUncompressedData = m_tUncompressedData; diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/SubArray.inl b/library/PolyVoxCore/include/PolyVoxCore/Impl/SubArray.inl index 49ae1ea0..c1285d60 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/SubArray.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/SubArray.inl @@ -21,14 +21,14 @@ misrepresented as being the original software. distribution. *******************************************************************************/ -#include +#include "PolyVoxCore/Impl/ErrorHandling.h" namespace PolyVox { template SubArray SubArray::operator[](uint32_t uIndex) { - assert(uIndex(&m_pElements[uIndex*m_pOffsets[0]], m_pDimensions+1, m_pOffsets+1); @@ -37,7 +37,7 @@ namespace PolyVox template const SubArray SubArray::operator[](uint32_t uIndex) const { - assert(uIndex(&m_pElements[uIndex*m_pOffsets[0]], m_pDimensions+1, m_pOffsets+1); @@ -56,14 +56,14 @@ namespace PolyVox template ElementType& SubArray<1, ElementType>::operator[] (uint32_t uIndex) { - assert(uIndex const ElementType& SubArray<1, ElementType>::operator[] (uint32_t uIndex) const { - assert(uIndex