diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h index ea5541e6..e27b5b09 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h @@ -26,7 +26,7 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Impl/TypeDef.h" -#include "PolyVoxCore/Compressor.h" +#include "PolyVoxCore/PolyVoxForwardDeclarations.h" #include "PolyVoxCore/Vector.h" #include diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl index b4abf7d6..374ae124 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl @@ -24,8 +24,7 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Impl/ErrorHandling.h" #include "PolyVoxCore/Impl/Utility.h" -#include "PolyVoxCore/MinizCompressor.h" -#include "PolyVoxCore/RLECompressor.h" +#include "PolyVoxCore/Compressor.h" #include "PolyVoxCore/Vector.h" #include "PolyVoxCore/Impl/ErrorHandling.h" diff --git a/library/PolyVoxCore/include/PolyVoxCore/RLECompressor.inl b/library/PolyVoxCore/include/PolyVoxCore/RLECompressor.inl index 600e2cf9..1b274d30 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RLECompressor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RLECompressor.inl @@ -17,7 +17,10 @@ namespace PolyVox template uint32_t RLECompressor::compress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength) { - assert(uSrcLength % sizeof(ValueType) == 0); + if(uSrcLength % sizeof(ValueType) != 0) + { + POLYVOX_THROW(std::length_error, "Source length must be a integer multiple of the ValueType size"); + } uSrcLength /= sizeof(ValueType); uDstLength /= sizeof(Run); @@ -60,7 +63,10 @@ namespace PolyVox template uint32_t RLECompressor::decompress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength) { - assert(uSrcLength % sizeof(Run) == 0); + if(uSrcLength % sizeof(Run) != 0) + { + POLYVOX_THROW(std::length_error, "Source length must be a integer multiple of the Run size"); + } uSrcLength /= sizeof(Run); uDstLength /= sizeof(ValueType); diff --git a/library/polyvoxcore/source/MinizCompressor.cpp b/library/polyvoxcore/source/MinizCompressor.cpp index f0dc06a6..30b7988c 100644 --- a/library/polyvoxcore/source/MinizCompressor.cpp +++ b/library/polyvoxcore/source/MinizCompressor.cpp @@ -9,11 +9,16 @@ #define MINIZ_NO_ZLIB_COMPATIBLE_NAMES //#define MINIZ_NO_MALLOC +#include "PolyVoxCore/Impl/ErrorHandling.h" // For some unknown reason the miniz library is supplied only as a // single .c file without a header. Apparently the only way to use // it is then to #include it directly which is what the examples do. #include "PolyVoxCore/Impl/miniz.c" +#include + +using namespace std; + namespace PolyVox { MinizCompressor::MinizCompressor() @@ -30,7 +35,12 @@ namespace PolyVox // Do the compression int result = mz_compress((unsigned char*)pDstData, &ulDstLength, (const unsigned char*) pSrcData, uSrcLength); - assert(result == MZ_OK); + if(result != MZ_OK) + { + stringstream ss; + ss << "mz_compress() failed with return code '" << result << "'"; + POLYVOX_THROW(std::runtime_error, ss.str()); + } // Return the number of bytes written to the output. return ulDstLength; @@ -41,7 +51,12 @@ namespace PolyVox mz_ulong ulDstLength = uDstLength; int result = mz_uncompress((unsigned char*) pDstData, &ulDstLength, (const unsigned char*) pSrcData, uSrcLength); - assert(result == MZ_OK); + if(result != MZ_OK) + { + stringstream ss; + ss << "mz_uncompress() failed with return code '" << result << "'"; + POLYVOX_THROW(std::runtime_error, ss.str()); + } return ulDstLength; } diff --git a/tests/testvolume.cpp b/tests/testvolume.cpp index 5d704760..74a3ffa1 100644 --- a/tests/testvolume.cpp +++ b/tests/testvolume.cpp @@ -24,6 +24,7 @@ freely, subject to the following restrictions: #include "testvolume.h" #include "PolyVoxCore/LargeVolume.h" +#include "PolyVoxCore/MinizCompressor.h" #include "PolyVoxCore/RawVolume.h" #include "PolyVoxCore/RLECompressor.h" #include "PolyVoxCore/SimpleVolume.h" @@ -270,7 +271,8 @@ TestVolume::TestVolume() { Region region(-57, -31, 12, 64, 96, 131); // Deliberatly awkward size - m_pCompressor = new RLECompressor; + //m_pCompressor = new RLECompressor; + m_pCompressor = new MinizCompressor; //Create the volumes m_pRawVolume = new RawVolume(region);