Merge pull request #46 from lvlonggame/v3

reader bug about 64bits.
This commit is contained in:
XiaoYang 2014-06-30 17:17:46 +08:00
commit e51828eb28
4 changed files with 23 additions and 15 deletions

View File

@ -463,11 +463,19 @@ bool Bundle3D::loadBinary(const std::string& path)
// Read version // Read version
unsigned char ver[2]; 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(); if (ver[0] != 0) {
CCLOGINFO(false, "Unsupported version: (%d, %d)", ver[0], ver[1]); clear();
return false; 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 // Read ref table size
@ -542,12 +550,12 @@ bool Bundle3D::loadMeshDataBinary(MeshData* meshdata)
} }
// Read index data // Read index data
ssize_t meshPartCount = 1; unsigned int meshPartCount = 1;
//_binaryReader.read(&meshPartCount, 4, 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) if (_binaryReader.read(&nIndexCount, 4, 1) != 1)
{ {
CCLOGINFO("Failed to read meshdata: nIndexCount '%s'.", _path.c_str()); CCLOGINFO("Failed to read meshdata: nIndexCount '%s'.", _path.c_str());
@ -702,24 +710,24 @@ bool Bundle3D::loadAnimationDataBinary(Animation3DData* animationdata)
return false; return false;
} }
ssize_t animNum; unsigned int animNum;
if (!_binaryReader.read(&animNum)) if (!_binaryReader.read(&animNum))
{ {
CCLOGINFO("Failed to read AnimationData: animNum '%s'.", _path.c_str()); CCLOGINFO("Failed to read AnimationData: animNum '%s'.", _path.c_str());
return false; return false;
} }
for (ssize_t i = 0; i < animNum; ++i) for (unsigned int i = 0; i < animNum; ++i)
{ {
std::string boneName = _binaryReader.readString(); std::string boneName = _binaryReader.readString();
ssize_t keyframeNum; unsigned int keyframeNum;
if (!_binaryReader.read(&keyframeNum)) if (!_binaryReader.read(&keyframeNum))
{ {
CCLOGINFO("Failed to read AnimationData: keyframeNum '%s'.", _path.c_str()); CCLOGINFO("Failed to read AnimationData: keyframeNum '%s'.", _path.c_str());
return false; return false;
} }
for (ssize_t j = 0; j < keyframeNum; ++j) for (unsigned int j = 0; j < keyframeNum; ++j)
{ {
float keytime; float keytime;
if (!_binaryReader.read(&keytime)) if (!_binaryReader.read(&keytime))
@ -808,7 +816,7 @@ unsigned int Bundle3D::parseGLProgramAttribute(const std::string& str)
void Bundle3D::getModelRelativePath(const std::string& path) void Bundle3D::getModelRelativePath(const std::string& path)
{ {
int index = path.find_last_of('/'); ssize_t index = path.find_last_of('/');
std::string fullModelPath; std::string fullModelPath;
fullModelPath = path.substr(0, index + 1); fullModelPath = path.substr(0, index + 1);

View File

@ -173,7 +173,7 @@ protected:
// for binary reading // for binary reading
Data* _binaryBuffer; Data* _binaryBuffer;
BundleReader _binaryReader; BundleReader _binaryReader;
size_t _referenceCount; unsigned int _referenceCount;
Reference* _references; Reference* _references;
bool _isBinary; bool _isBinary;

View File

@ -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_position = 0;
m_buffer = lpbuffer; m_buffer = lpbuffer;

View File

@ -55,7 +55,7 @@ public:
* @param lpbuffer The data buffer pointer * @param lpbuffer The data buffer pointer
* @param length The data buffer size * @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. * Reads an array of elements.