Merge pull request #47 from lvlonggame/v3

modify bundle3d version and bundleReader
This commit is contained in:
XiaoYang 2014-07-01 13:16:14 +08:00
commit 5666033faf
3 changed files with 21 additions and 18 deletions

View File

@ -447,8 +447,7 @@ bool Bundle3D::loadBinary(const std::string& path)
return false; return false;
} }
// Create bundle reader // Initialise bundle reader
//CC_SAFE_DELETE(_bundleReader);
_binaryReader.init( (char*)_binaryBuffer->getBytes(), _binaryBuffer->getSize() ); _binaryReader.init( (char*)_binaryBuffer->getBytes(), _binaryBuffer->getSize() );
// Read identifier info // Read identifier info
@ -463,21 +462,24 @@ 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) if (_binaryReader.read(ver, 1, 2)!= 2){
{ CCLOG("Failed to read version:");
if (ver[0] != 0) { return false;
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;
}
} }
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 // Read ref table size
if (_binaryReader.read(&_referenceCount, 4, 1) != 1) if (_binaryReader.read(&_referenceCount, 4, 1) != 1)
{ {

View File

@ -65,7 +65,7 @@ char* BundleReader::readLine(int num,char* line)
char* p = line; char* p = line;
char c; char c;
ssize_t readNum = 0; ssize_t readNum = 0;
while((c=*buffer) != 10 && readNum < (ssize_t)num && m_position<(long int)m_length) while((c=*buffer) != 10 && readNum < (ssize_t)num && m_position < m_length)
{ {
*p = c; *p = c;
p++; p++;
@ -91,7 +91,7 @@ ssize_t BundleReader::length()
return m_length; return m_length;
} }
long int BundleReader::tell() ssize_t BundleReader::tell()
{ {
if (!m_buffer) if (!m_buffer)
return -1; return -1;

View File

@ -112,7 +112,7 @@ public:
bool readMatrix(float* m); bool readMatrix(float* m);
private: private:
long int m_position; ssize_t m_position;
ssize_t m_length; ssize_t m_length;
char* m_buffer; char* m_buffer;
}; };
@ -136,6 +136,7 @@ inline bool BundleReader::readArray(unsigned int *length, std::vector<T> *values
{ {
return false; return false;
} }
if (*length > 0 && values) if (*length > 0 && values)
{ {
values->resize(*length); values->resize(*length);