|
@@ -89,7 +89,7 @@ size_t Write<unsigned int>(IOStream * stream, const unsigned int& w) {
|
|
|
const uint32_t t = (uint32_t)w;
|
|
|
if (w > t) {
|
|
|
// this shouldn't happen, integers in Assimp data structures never exceed 2^32
|
|
|
- throw new DeadlyExportError("loss of data due to 64 -> 32 bit integer conversion");
|
|
|
+ throw DeadlyExportError("loss of data due to 64 -> 32 bit integer conversion");
|
|
|
}
|
|
|
|
|
|
stream->Write(&t,4,1);
|
|
@@ -805,10 +805,16 @@ public:
|
|
|
WriteBinaryScene( &uncompressedStream, pScene );
|
|
|
|
|
|
uLongf uncompressedSize = static_cast<uLongf>(uncompressedStream.Tell());
|
|
|
- uLongf compressedSize = (uLongf)(uncompressedStream.Tell() * 1.001 + 12.);
|
|
|
+ uLongf compressedSize = (uLongf)compressBound(uncompressedSize);
|
|
|
uint8_t* compressedBuffer = new uint8_t[ compressedSize ];
|
|
|
|
|
|
- compress2( compressedBuffer, &compressedSize, (const Bytef*)uncompressedStream.GetBufferPointer(), uncompressedSize, 9 );
|
|
|
+ int res = compress2( compressedBuffer, &compressedSize, (const Bytef*)uncompressedStream.GetBufferPointer(), uncompressedSize, 9 );
|
|
|
+ if(res != Z_OK)
|
|
|
+ {
|
|
|
+ delete [] compressedBuffer;
|
|
|
+ pIOSystem->Close(out);
|
|
|
+ throw DeadlyExportError("Compression failed.");
|
|
|
+ }
|
|
|
|
|
|
out->Write( &uncompressedSize, sizeof(uint32_t), 1 );
|
|
|
out->Write( compressedBuffer, sizeof(char), compressedSize );
|