From df7ab500629ddd82f6c7a3d957a0b57433fd9766 Mon Sep 17 00:00:00 2001 From: lvlong Date: Tue, 1 Jul 2014 09:26:21 +0800 Subject: [PATCH] modify BundleReader and the version read --- cocos/3d/CCBundle3D.cpp | 29 ++++++++++++++++------------- cocos/3d/CCBundleReader.cpp | 4 ++-- cocos/3d/CCBundleReader.h | 2 +- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/cocos/3d/CCBundle3D.cpp b/cocos/3d/CCBundle3D.cpp index cd6bc42f9a..00aa893a05 100644 --- a/cocos/3d/CCBundle3D.cpp +++ b/cocos/3d/CCBundle3D.cpp @@ -463,20 +463,23 @@ bool Bundle3D::loadBinary(const std::string& path) // Read version unsigned char ver[2]; - if (_binaryReader.read(ver, 1, 2) == 2) - { - 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; - } + if (_binaryReader.read(ver, 1, 2)!= 2){ + CCLOG("Failed to read version:"); + 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 if (_binaryReader.read(&_referenceCount, 4, 1) != 1) diff --git a/cocos/3d/CCBundleReader.cpp b/cocos/3d/CCBundleReader.cpp index 2bdeda2c43..6cdcbbd0e9 100644 --- a/cocos/3d/CCBundleReader.cpp +++ b/cocos/3d/CCBundleReader.cpp @@ -65,7 +65,7 @@ char* BundleReader::readLine(int num,char* line) char* p = line; char c; 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++; @@ -91,7 +91,7 @@ ssize_t BundleReader::length() return m_length; } -long int BundleReader::tell() +ssize_t BundleReader::tell() { if (!m_buffer) return -1; diff --git a/cocos/3d/CCBundleReader.h b/cocos/3d/CCBundleReader.h index b991412d8f..37cebd21d6 100644 --- a/cocos/3d/CCBundleReader.h +++ b/cocos/3d/CCBundleReader.h @@ -112,7 +112,7 @@ public: bool readMatrix(float* m); private: - long int m_position; + ssize_t m_position; ssize_t m_length; char* m_buffer; };