diff --git a/cocos/3d/CCBundle3D.cpp b/cocos/3d/CCBundle3D.cpp index 78fe4462f7..cd6bc42f9a 100644 --- a/cocos/3d/CCBundle3D.cpp +++ b/cocos/3d/CCBundle3D.cpp @@ -463,11 +463,19 @@ bool Bundle3D::loadBinary(const std::string& path) // Read version unsigned char ver[2]; - if (_binaryReader.read(ver, 1, 2) != 2 || ver[0] != 0 || ver[1] != 1) + if (_binaryReader.read(ver, 1, 2) == 2) { - clear(); - CCLOGINFO(false, "Unsupported version: (%d, %d)", ver[0], ver[1]); - return false; + if (ver[0] != 0) { + clear(); + CCLOGINFO(false, "Unsupported version: (%d, %d)", ver[0], ver[1]); + return false; + } + + if (ver[1] <= 0 || ver[1] > 2) { + clear(); + CCLOGINFO(false, "Unsupported version: (%d, %d)", ver[0], ver[1]); + return false; + } } // Read ref table size @@ -542,12 +550,12 @@ bool Bundle3D::loadMeshDataBinary(MeshData* meshdata) } // Read index data - ssize_t meshPartCount = 1; + unsigned int meshPartCount = 1; //_binaryReader.read(&meshPartCount, 4, 1); - for (ssize_t i = 0; i < meshPartCount; ++i) + for (unsigned int i = 0; i < meshPartCount; ++i) { - ssize_t nIndexCount; + unsigned int nIndexCount; if (_binaryReader.read(&nIndexCount, 4, 1) != 1) { CCLOGINFO("Failed to read meshdata: nIndexCount '%s'.", _path.c_str()); @@ -702,24 +710,24 @@ bool Bundle3D::loadAnimationDataBinary(Animation3DData* animationdata) return false; } - ssize_t animNum; + unsigned int animNum; if (!_binaryReader.read(&animNum)) { CCLOGINFO("Failed to read AnimationData: animNum '%s'.", _path.c_str()); return false; } - for (ssize_t i = 0; i < animNum; ++i) + for (unsigned int i = 0; i < animNum; ++i) { std::string boneName = _binaryReader.readString(); - ssize_t keyframeNum; + unsigned int keyframeNum; if (!_binaryReader.read(&keyframeNum)) { CCLOGINFO("Failed to read AnimationData: keyframeNum '%s'.", _path.c_str()); return false; } - for (ssize_t j = 0; j < keyframeNum; ++j) + for (unsigned int j = 0; j < keyframeNum; ++j) { float keytime; if (!_binaryReader.read(&keytime)) @@ -808,7 +816,7 @@ unsigned int Bundle3D::parseGLProgramAttribute(const std::string& str) void Bundle3D::getModelRelativePath(const std::string& path) { - int index = path.find_last_of('/'); + ssize_t index = path.find_last_of('/'); std::string fullModelPath; fullModelPath = path.substr(0, index + 1); diff --git a/cocos/3d/CCBundle3D.h b/cocos/3d/CCBundle3D.h index 6717117f3c..f3a6319ed6 100644 --- a/cocos/3d/CCBundle3D.h +++ b/cocos/3d/CCBundle3D.h @@ -173,7 +173,7 @@ protected: // for binary reading Data* _binaryBuffer; BundleReader _binaryReader; - size_t _referenceCount; + unsigned int _referenceCount; Reference* _references; bool _isBinary; diff --git a/cocos/3d/CCBundleReader.cpp b/cocos/3d/CCBundleReader.cpp index 7d7651e15e..2bdeda2c43 100644 --- a/cocos/3d/CCBundleReader.cpp +++ b/cocos/3d/CCBundleReader.cpp @@ -15,7 +15,7 @@ BundleReader::~BundleReader() }; -void BundleReader::init(char* lpbuffer, unsigned int length) +void BundleReader::init(char* lpbuffer, ssize_t length) { m_position = 0; m_buffer = lpbuffer; diff --git a/cocos/3d/CCBundleReader.h b/cocos/3d/CCBundleReader.h index dc42d76f95..b991412d8f 100644 --- a/cocos/3d/CCBundleReader.h +++ b/cocos/3d/CCBundleReader.h @@ -55,7 +55,7 @@ public: * @param lpbuffer The data buffer pointer * @param length The data buffer size */ - void init(char* lpbuffer, unsigned int length); + void init(char* lpbuffer, ssize_t length); /** * Reads an array of elements.