From 3ffc026c6caee671ed0b181fccbf80efa268a620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89loi=20Rivard?= Date: Tue, 23 Jul 2013 14:44:08 +0200 Subject: [PATCH 1/2] Added some guards in file utils. --- AUTHORS | 1 + cocos2dx/platform/android/CCFileUtilsAndroid.cpp | 7 ++++++- cocos2dx/platform/emscripten/CCFileUtilsEmscripten.cpp | 7 ++++++- cocos2dx/platform/ios/CCFileUtilsIOS.mm | 7 ++++++- cocos2dx/platform/linux/CCFileUtilsLinux.cpp | 7 ++++++- cocos2dx/platform/mac/CCFileUtilsMac.mm | 7 ++++++- cocos2dx/platform/nacl/CCFileUtilsNaCl.cpp | 7 ++++++- cocos2dx/platform/tizen/CCFileUtilsTizen.cpp | 7 ++++++- cocos2dx/platform/win32/CCFileUtilsWin32.cpp | 7 ++++++- 9 files changed, 49 insertions(+), 8 deletions(-) diff --git a/AUTHORS b/AUTHORS index e6c188c28a..0909545120 100644 --- a/AUTHORS +++ b/AUTHORS @@ -416,6 +416,7 @@ Developers: Refactored emscripten-build.sh, it's no longer need to be edited to make emscripten work. Creation of CCDeprecated-ext.h Use of a single emscripten HTML template file. + Added some guards in fileutils elmiro Correction of passed buffer size to readlink and verification of result return by readlink. diff --git a/cocos2dx/platform/android/CCFileUtilsAndroid.cpp b/cocos2dx/platform/android/CCFileUtilsAndroid.cpp index a31de560ff..56cda63c06 100644 --- a/cocos2dx/platform/android/CCFileUtilsAndroid.cpp +++ b/cocos2dx/platform/android/CCFileUtilsAndroid.cpp @@ -59,7 +59,12 @@ FileUtils* FileUtils::getInstance() if (s_sharedFileUtils == NULL) { s_sharedFileUtils = new FileUtilsAndroid(); - s_sharedFileUtils->init(); + if(!s_sharedFileUtils->init()) + { + delete s_sharedFileUtils; + s_sharedFileUtils = NULL; + CCLOG("ERROR: Could not init CCFileUtilsAndroid"); + } } return s_sharedFileUtils; } diff --git a/cocos2dx/platform/emscripten/CCFileUtilsEmscripten.cpp b/cocos2dx/platform/emscripten/CCFileUtilsEmscripten.cpp index 6e1094ff7d..7908ca6ad9 100644 --- a/cocos2dx/platform/emscripten/CCFileUtilsEmscripten.cpp +++ b/cocos2dx/platform/emscripten/CCFileUtilsEmscripten.cpp @@ -14,7 +14,12 @@ FileUtils* FileUtils::getInstance() if (s_sharedFileUtils == NULL) { s_sharedFileUtils = new FileUtilsEmscripten(); - s_sharedFileUtils->init(); + if(!s_sharedFileUtils->init()) + { + delete s_sharedFileUtils; + s_sharedFileUtils = NULL; + CCLOG("ERROR: Could not init CCFileUtilsEmscripten"); + } } return s_sharedFileUtils; } diff --git a/cocos2dx/platform/ios/CCFileUtilsIOS.mm b/cocos2dx/platform/ios/CCFileUtilsIOS.mm index 5eb9e0e772..519353c367 100644 --- a/cocos2dx/platform/ios/CCFileUtilsIOS.mm +++ b/cocos2dx/platform/ios/CCFileUtilsIOS.mm @@ -213,7 +213,12 @@ FileUtils* FileUtils::getInstance() if (s_sharedFileUtils == NULL) { s_sharedFileUtils = new FileUtilsIOS(); - s_sharedFileUtils->init(); + if(!s_sharedFileUtils->init()) + { + delete s_sharedFileUtils; + s_sharedFileUtils = NULL; + CCLOG("ERROR: Could not init CCFileUtilsIOS"); + } } return s_sharedFileUtils; } diff --git a/cocos2dx/platform/linux/CCFileUtilsLinux.cpp b/cocos2dx/platform/linux/CCFileUtilsLinux.cpp index d8d19a25ea..90ff1e0e04 100644 --- a/cocos2dx/platform/linux/CCFileUtilsLinux.cpp +++ b/cocos2dx/platform/linux/CCFileUtilsLinux.cpp @@ -23,7 +23,12 @@ FileUtils* FileUtils::getInstance() if (s_sharedFileUtils == NULL) { s_sharedFileUtils = new FileUtilsLinux(); - s_sharedFileUtils->init(); + if(!s_sharedFileUtils->init()) + { + delete s_sharedFileUtils; + s_sharedFileUtils = NULL; + CCLOG("ERROR: Could not init CCFileUtilsLinux"); + } } return s_sharedFileUtils; } diff --git a/cocos2dx/platform/mac/CCFileUtilsMac.mm b/cocos2dx/platform/mac/CCFileUtilsMac.mm index 03766ee554..426a42149c 100644 --- a/cocos2dx/platform/mac/CCFileUtilsMac.mm +++ b/cocos2dx/platform/mac/CCFileUtilsMac.mm @@ -210,7 +210,12 @@ FileUtils* FileUtils::getInstance() if (s_sharedFileUtils == NULL) { s_sharedFileUtils = new FileUtilsMac(); - s_sharedFileUtils->init(); + if(!s_sharedFileUtils->init()) + { + delete s_sharedFileUtils; + s_sharedFileUtils = NULL; + CCLOG("ERROR: Could not init CCFileUtilsMac"); + } } return s_sharedFileUtils; } diff --git a/cocos2dx/platform/nacl/CCFileUtilsNaCl.cpp b/cocos2dx/platform/nacl/CCFileUtilsNaCl.cpp index a9d0a9e773..631d94dca2 100644 --- a/cocos2dx/platform/nacl/CCFileUtilsNaCl.cpp +++ b/cocos2dx/platform/nacl/CCFileUtilsNaCl.cpp @@ -35,7 +35,12 @@ FileUtils* FileUtils::getInstance() if (s_sharedFileUtils == NULL) { s_sharedFileUtils = new FileUtilsNaCl(); - s_sharedFileUtils->init(); + if(!s_sharedFileUtils->init()) + { + delete s_sharedFileUtils; + s_sharedFileUtils = NULL; + CCLOG("ERROR: Could not init CCFileUtilsNacl"); + } } return s_sharedFileUtils; } diff --git a/cocos2dx/platform/tizen/CCFileUtilsTizen.cpp b/cocos2dx/platform/tizen/CCFileUtilsTizen.cpp index b01f273bd7..dad418107f 100644 --- a/cocos2dx/platform/tizen/CCFileUtilsTizen.cpp +++ b/cocos2dx/platform/tizen/CCFileUtilsTizen.cpp @@ -45,7 +45,12 @@ FileUtils* FileUtils::getInstance() if (s_sharedFileUtils == NULL) { s_sharedFileUtils = new FileUtilsTizen(); - s_sharedFileUtils->init(); + if(!s_sharedFileUtils->init()) + { + delete s_sharedFileUtils; + s_sharedFileUtils = NULL; + CCLOG("ERROR: Could not init CCFileUtilsTizen"); + } } return s_sharedFileUtils; } diff --git a/cocos2dx/platform/win32/CCFileUtilsWin32.cpp b/cocos2dx/platform/win32/CCFileUtilsWin32.cpp index 9c34e2a107..460e2400df 100644 --- a/cocos2dx/platform/win32/CCFileUtilsWin32.cpp +++ b/cocos2dx/platform/win32/CCFileUtilsWin32.cpp @@ -48,7 +48,12 @@ FileUtils* FileUtils::getInstance() if (s_sharedFileUtils == NULL) { s_sharedFileUtils = new FileUtilsWin32(); - s_sharedFileUtils->init(); + if(!s_sharedFileUtils->init()) + { + delete s_sharedFileUtils; + s_sharedFileUtils = NULL; + CCLOG("ERROR: Could not init CCFileUtilsWin32"); + } } return s_sharedFileUtils; } From 95b826d82aa1149cd2caa55ac6e2ec14e7569040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89loi=20Rivard?= Date: Tue, 23 Jul 2013 15:49:00 +0200 Subject: [PATCH 2/2] Fixed a bug in emscripten file utils. --- AUTHORS | 2 +- cocos2dx/platform/CCImageCommon_cpp.h | 4 ++-- cocos2dx/platform/emscripten/CCFileUtilsEmscripten.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/AUTHORS b/AUTHORS index 0909545120..bf930df9b2 100644 --- a/AUTHORS +++ b/AUTHORS @@ -416,7 +416,7 @@ Developers: Refactored emscripten-build.sh, it's no longer need to be edited to make emscripten work. Creation of CCDeprecated-ext.h Use of a single emscripten HTML template file. - Added some guards in fileutils + Added some guards in fileutils. Fixed a bug in emscripten file utils. elmiro Correction of passed buffer size to readlink and verification of result return by readlink. diff --git a/cocos2dx/platform/CCImageCommon_cpp.h b/cocos2dx/platform/CCImageCommon_cpp.h index 6a35d53eec..bdd3d40121 100644 --- a/cocos2dx/platform/CCImageCommon_cpp.h +++ b/cocos2dx/platform/CCImageCommon_cpp.h @@ -94,13 +94,14 @@ Image::~Image() bool Image::initWithImageFile(const char * strPath, Format eImgFmt/* = eFmtPng*/) { bool bRet = false; + std::string fullPath = FileUtils::getInstance()->fullPathForFilename(strPath); #ifdef EMSCRIPTEN // Emscripten includes a re-implementation of SDL that uses HTML5 canvas // operations underneath. Consequently, loading images via IMG_Load (an SDL // API) will be a lot faster than running libpng et al as compiled with // Emscripten. - SDL_Surface *iSurf = IMG_Load(strPath); + SDL_Surface *iSurf = IMG_Load(fullPath.c_str()); int size = 4 * (iSurf->w * iSurf->h); bRet = initWithRawData((void*)iSurf->pixels, size, iSurf->w, iSurf->h, 8, true); @@ -116,7 +117,6 @@ bool Image::initWithImageFile(const char * strPath, Format eImgFmt/* = eFmtPng*/ SDL_FreeSurface(iSurf); #else unsigned long nSize = 0; - std::string fullPath = FileUtils::getInstance()->fullPathForFilename(strPath); unsigned char* pBuffer = FileUtils::getInstance()->getFileData(fullPath.c_str(), "rb", &nSize); if (pBuffer != NULL && nSize > 0) { diff --git a/cocos2dx/platform/emscripten/CCFileUtilsEmscripten.cpp b/cocos2dx/platform/emscripten/CCFileUtilsEmscripten.cpp index 7908ca6ad9..f21ff121fa 100644 --- a/cocos2dx/platform/emscripten/CCFileUtilsEmscripten.cpp +++ b/cocos2dx/platform/emscripten/CCFileUtilsEmscripten.cpp @@ -29,7 +29,7 @@ FileUtilsEmscripten::FileUtilsEmscripten() bool FileUtilsEmscripten::init() { - _defaultResRootPath = "app/native/Resources/"; + _defaultResRootPath = "/"; return FileUtils::init(); }