From 43a466453418a9a71b9524dd3777ea26d0b698cc Mon Sep 17 00:00:00 2001 From: Walzer Date: Thu, 2 Sep 2010 07:31:37 +0000 Subject: [PATCH] issue #114, CCTMXTiledMap debug --- cocos2dx/particle_nodes/CCParticleSystem.cpp | 7 ++++++- cocos2dx/support/base64.cpp | 4 ++-- cocos2dx/tileMap_parallax_nodes/CCTMXLayer.cpp | 5 +++-- .../tileMap_parallax_nodes/CCTMXTiledMap.cpp | 16 ++++++++-------- .../tileMap_parallax_nodes/CCTMXXMLParser.cpp | 3 ++- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/cocos2dx/particle_nodes/CCParticleSystem.cpp b/cocos2dx/particle_nodes/CCParticleSystem.cpp index b6a584324f..248e0b717c 100644 --- a/cocos2dx/particle_nodes/CCParticleSystem.cpp +++ b/cocos2dx/particle_nodes/CCParticleSystem.cpp @@ -257,10 +257,15 @@ namespace cocos2d { bRet = true; } } while (0); - CCX_SAFE_FREE(buffer); + if (buffer) + { + delete [] buffer; + buffer = NULL; + } if(deflated) { delete [] deflated; + deflated = NULL; } CCX_SAFE_DELETE(image); return bRet; diff --git a/cocos2dx/support/base64.cpp b/cocos2dx/support/base64.cpp index a4ccdd969c..c11f8b0b62 100644 --- a/cocos2dx/support/base64.cpp +++ b/cocos2dx/support/base64.cpp @@ -93,14 +93,14 @@ int base64Decode(unsigned char *in, unsigned int inLength, unsigned char **out) unsigned int outLength = 0; //should be enough to store 6-bit buffers in 8-bit buffers - *out = (unsigned char *)malloc( (size_t)(inLength * 3.0f / 4.0f + 1)); + *out = new unsigned char[(size_t)(inLength * 3.0f / 4.0f + 1)]; if( *out ) { int ret = _base64Decode(in, inLength, *out, &outLength); if (ret > 0 ) { std::printf("Base64Utils: error decoding"); - free(*out); + delete [] *out; *out = NULL; outLength = 0; } diff --git a/cocos2dx/tileMap_parallax_nodes/CCTMXLayer.cpp b/cocos2dx/tileMap_parallax_nodes/CCTMXLayer.cpp index 3507779ee8..d3a7d73d92 100644 --- a/cocos2dx/tileMap_parallax_nodes/CCTMXLayer.cpp +++ b/cocos2dx/tileMap_parallax_nodes/CCTMXLayer.cpp @@ -64,12 +64,13 @@ namespace cocos2d { m_uMinGID = layerInfo->m_uMinGID; m_uMaxGID = layerInfo->m_uMaxGID; m_cOpacity = layerInfo->m_cOpacity; - if (!layerInfo->m_pProperties && layerInfo->m_pProperties->size()>0) + m_pProperties = new StringToStringDictionary(); + if (layerInfo->m_pProperties && layerInfo->m_pProperties->size()>0) { StringToStringDictionary::iterator it; for (it = layerInfo->m_pProperties->begin(); it != layerInfo->m_pProperties->end(); ++it) { - m_pProperties->insert(*it); + m_pProperties->insert(StringToStringPair(it->first, it->second)); } } diff --git a/cocos2dx/tileMap_parallax_nodes/CCTMXTiledMap.cpp b/cocos2dx/tileMap_parallax_nodes/CCTMXTiledMap.cpp index df5036b1f5..ae3fe0e368 100644 --- a/cocos2dx/tileMap_parallax_nodes/CCTMXTiledMap.cpp +++ b/cocos2dx/tileMap_parallax_nodes/CCTMXTiledMap.cpp @@ -60,11 +60,11 @@ namespace cocos2d{ int idx = 0; - if (mapInfo->getLayers() && mapInfo->getLayers()->count()>0) + NSMutableArray* layers = mapInfo->getLayers(); + if (layers && layers->count()>0) { CCTMXLayerInfo *layerInfo = NULL; NSMutableArray::NSMutableArrayIterator it; - NSMutableArray* layers = mapInfo->getLayers(); for (it = layers->begin(); it != layers->end(); ++it) { layerInfo = *it; @@ -128,12 +128,12 @@ namespace cocos2d{ //CFByteOrder o = CFByteOrderGetCurrent(); CGSize size = layerInfo->m_tLayerSize; - - if (mapInfo->getTilesets() && mapInfo->getTilesets()->count()>0) + NSMutableArray* tilesets = mapInfo->getTilesets(); + if (tilesets && tilesets->count()>0) { CCTMXTilesetInfo *tileset = NULL; NSMutableArray::NSMutableArrayRevIterator rit; - for (rit = mapInfo->getTilesets()->rbegin(); rit != mapInfo->getTilesets()->rend(); ++rit) + for (rit = tilesets->rbegin(); rit != tilesets->rend(); ++rit) { tileset = *rit; if (tileset) @@ -195,11 +195,11 @@ namespace cocos2d{ CCTMXObjectGroup * CCTMXTiledMap::objectGroupNamed(const char *groupName) { std::string sGroupName = groupName; - if (m_pChildren && m_pChildren->count()>0) + if (m_pObjectGroups && m_pObjectGroups->count()>0) { CCTMXObjectGroup *objectGroup; - NSMutableArray::NSMutableArrayIterator it; - for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it) + NSMutableArray::NSMutableArrayIterator it; + for (it = m_pObjectGroups->begin(); it != m_pObjectGroups->end(); ++it) { objectGroup = (CCTMXObjectGroup*)(*it); if (objectGroup && objectGroup->getGroupName() == sGroupName) diff --git a/cocos2dx/tileMap_parallax_nodes/CCTMXXMLParser.cpp b/cocos2dx/tileMap_parallax_nodes/CCTMXXMLParser.cpp index 7d96d05377..c294fc8301 100644 --- a/cocos2dx/tileMap_parallax_nodes/CCTMXXMLParser.cpp +++ b/cocos2dx/tileMap_parallax_nodes/CCTMXXMLParser.cpp @@ -470,7 +470,8 @@ namespace cocos2d { { unsigned char *deflated; ZipUtils::inflateMemory(buffer, len, &deflated); - free( buffer ); + delete [] buffer; + buffer = NULL; if( ! deflated ) {