diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl index 2849b838..65325b65 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl @@ -210,13 +210,21 @@ namespace PolyVox pUncompressedData += m_vecCompressedData[ct].length; }*/ + m_tUncompressedData = new VoxelType[m_uSideLength * m_uSideLength * m_uSideLength]; + Data src; src.ptr = m_pCompressedData; src.length = m_uCompressedDataLength; - Data uncompressedResult = polyvox_decompress(src); + Data dst; + dst.ptr = reinterpret_cast(m_tUncompressedData); + dst.length = m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType); - m_tUncompressedData = reinterpret_cast(uncompressedResult.ptr); + polyvox_decompress(src, dst); + + POLYVOX_ASSERT(dst.length == m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType), "Destination length has changed."); + + //m_tUncompressedData = reinterpret_cast(uncompressedResult.ptr); m_bIsCompressed = false; m_bIsUncompressedDataModified = false; diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Compression.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Compression.h index 7d507e6b..6c98b4a0 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Compression.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Compression.h @@ -33,6 +33,6 @@ struct Data }; Data polyvox_compress(Data src); -Data polyvox_decompress(Data src); +void polyvox_decompress(Data src, Data dst); #endif //__PolyVox_Compression_H__ \ No newline at end of file diff --git a/library/polyvoxcore/source/Impl/Compression.cpp b/library/polyvoxcore/source/Impl/Compression.cpp index d94affaa..d533b430 100644 --- a/library/polyvoxcore/source/Impl/Compression.cpp +++ b/library/polyvoxcore/source/Impl/Compression.cpp @@ -37,27 +37,27 @@ Data polyvox_compress(Data src) return dst; } -Data polyvox_decompress(Data src) +void polyvox_decompress(Data src, Data dst) { - unsigned char* buffer; + /*unsigned char* buffer; mz_ulong uncompressedDataLength = 1000000; - buffer = new unsigned char[uncompressedDataLength]; + buffer = new unsigned char[uncompressedDataLength];*/ - int iUncompressionResult = uncompress(buffer, &uncompressedDataLength, src.ptr, src.length); + int iUncompressionResult = uncompress(dst.ptr, &dst.length, src.ptr, src.length); if (iUncompressionResult != Z_OK) { - delete[] buffer; + //delete[] buffer; POLYVOX_THROW(std::runtime_error, "Data decompression failed."); } - Data dst; + /*Data dst; dst.length = uncompressedDataLength; dst.ptr = new uint8_t[dst.length]; memcpy(dst.ptr, buffer, uncompressedDataLength); - delete[] buffer; + delete[] buffer;*/ - return dst; + //return dst; } \ No newline at end of file