Skip to content

Commit 05aaef3

Browse files
committed
STEVE: extra logging to figure out android asset loading issues
1 parent 38bc673 commit 05aaef3

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

cocos/2d/CCSpriteFrameCache.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(ValueMap& dictionary, Textu
292292
}
293293
// add sprite frame
294294
_spriteFrames.insert(spriteFrameName, spriteFrame);
295+
//STEVE CCLOG("[sctest] spriteFrameName = %s", spriteFrameName.c_str());
295296
}
296297
CC_SAFE_DELETE(image);
297298
}
@@ -352,6 +353,7 @@ void SpriteFrameCache::addSpriteFramesWithFile(const std::string& plist, Texture
352353
{
353354
if (_loadedFileNames->find(plist) != _loadedFileNames->end())
354355
{
356+
CCLOG("[todo: move to LOGINFO] sprite sheet already exists in cache!");
355357
return; // We already added it
356358
}
357359

cocos/platform/CCFileUtils.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,8 @@ void FileUtils::purgeCachedEntries()
623623
std::string FileUtils::getStringFromFile(const std::string& filename)
624624
{
625625
std::string s;
626-
getContents(filename, &s);
626+
auto status = getContents(filename, &s);
627+
CCLOG("[steve] status = %d", status);
627628
return s;
628629
}
629630

@@ -664,8 +665,10 @@ FileUtils::Status FileUtils::getContents(const std::string& filename, ResizableB
664665
return Status::NotExists;
665666

666667
FILE *fp = fopen(fs->getSuitableFOpen(fullPath).c_str(), "rb");
667-
if (!fp)
668+
if (!fp) {
669+
CCLOG("[steve] Error: %d (%s)\n", errno, strerror(errno));
668670
return Status::OpenFailed;
671+
}
669672

670673
#if defined(_MSC_VER)
671674
auto descriptor = _fileno(fp);

cocos/platform/android/CCFileUtils-android.cpp

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ FileUtilsAndroid::~FileUtilsAndroid()
8989
bool FileUtilsAndroid::init()
9090
{
9191
_defaultResRootPath = ASSETS_FOLDER_NAME;
92-
92+
9393
std::string assetsPath(getApkPath());
9494
if (assetsPath.find("/obb/") != std::string::npos)
9595
{
@@ -165,9 +165,16 @@ bool FileUtilsAndroid::isFileExistInternal(const std::string& strFilePath) const
165165
{
166166
const char* s = strFilePath.c_str();
167167

168+
CCLOG("[FileUtilsAndroid::isFileExistInternal] [steve] _defaultResRootPath: %s", _defaultResRootPath.c_str());
169+
168170
// Found "assets/" at the beginning of the path and we don't want it
169-
if (strFilePath.find(_defaultResRootPath) == 0) s += _defaultResRootPath.length();
170-
171+
if (strFilePath.find(_defaultResRootPath) == 0) {
172+
CCLOG("[steve] strFilePath: %s", strFilePath.c_str());
173+
s += _defaultResRootPath.length();
174+
}
175+
176+
CCLOG("[FileUtilsAndroid::isFileExistInternal] [steve] find in apk dirPath(%s)", s);
177+
171178
if (obbfile && obbfile->fileExists(s))
172179
{
173180
bFound = true;
@@ -180,7 +187,7 @@ bool FileUtilsAndroid::isFileExistInternal(const std::string& strFilePath) const
180187
bFound = true;
181188
AAsset_close(aa);
182189
} else {
183-
// CCLOG("[AssetManager] ... in APK %s, found = false!", strFilePath.c_str());
190+
CCLOG("[FileUtilsAndroid::isFileExistInternal] [steve] [AssetManager] ... in APK %s, found = false!", strFilePath.c_str());
184191
}
185192
}
186193
}
@@ -204,11 +211,11 @@ bool FileUtilsAndroid::isDirectoryExistInternal(const std::string& dirPath) cons
204211
}
205212

206213
const char* s = dirPath.c_str();
207-
214+
208215
// find absolute path in flash memory
209216
if (s[0] == '/')
210217
{
211-
CCLOG("find in flash memory dirPath(%s)", s);
218+
CCLOG("[FileUtilsAndroid::isDirectoryExistInternal] find in flash memory dirPath(%s)", s);
212219
struct stat st;
213220
if (stat(s, &st) == 0)
214221
{
@@ -219,7 +226,7 @@ bool FileUtilsAndroid::isDirectoryExistInternal(const std::string& dirPath) cons
219226
{
220227
// find it in apk's assets dir
221228
// Found "assets/" at the beginning of the path and we don't want it
222-
CCLOG("find in apk dirPath(%s)", s);
229+
CCLOG("[FileUtilsAndroid::isDirectoryExistInternal] find in apk dirPath(%s)", s);
223230
if (dirPath.find(ASSETS_FOLDER_NAME) == 0)
224231
{
225232
s += ASSETS_FOLDER_NAME_LENGTH;
@@ -234,7 +241,7 @@ bool FileUtilsAndroid::isDirectoryExistInternal(const std::string& dirPath) cons
234241
}
235242
}
236243
}
237-
244+
238245
return false;
239246
}
240247

@@ -285,32 +292,36 @@ FileUtils::Status FileUtilsAndroid::getContents(const std::string& filename, Res
285292

286293
string fullPath = fullPathForFilename(filename);
287294

288-
if (fullPath[0] == '/')
295+
if (fullPath[0] == '/') {
289296
return FileUtils::getContents(fullPath, buffer);
297+
}
290298

291299
string relativePath = string();
292300
size_t position = fullPath.find(apkprefix);
293301
if (0 == position) {
302+
CCLOG("[sctest] find in apk dirPath(%s)", fullPath.c_str());
294303
// "assets/" is at the beginning of the path and we don't want it
295304
relativePath += fullPath.substr(apkprefix.size());
296305
} else {
297306
relativePath = fullPath;
298307
}
299-
308+
309+
CCLOG("[sctest] relativePath: %s", relativePath.c_str());
310+
300311
if (obbfile)
301312
{
302313
if (obbfile->getFileData(relativePath, buffer))
303314
return FileUtils::Status::OK;
304315
}
305316

306317
if (nullptr == assetmanager) {
307-
LOGD("... FileUtilsAndroid::assetmanager is nullptr");
318+
LOGD("[sctest] ... FileUtilsAndroid::assetmanager is nullptr");
308319
return FileUtils::Status::NotInitialized;
309320
}
310321

311322
AAsset* asset = AAssetManager_open(assetmanager, relativePath.data(), AASSET_MODE_UNKNOWN);
312323
if (nullptr == asset) {
313-
LOGD("asset is nullptr");
324+
LOGD("[sctest] asset is nullptr: %s", relativePath.c_str());
314325
return FileUtils::Status::OpenFailed;
315326
}
316327

@@ -326,6 +337,7 @@ FileUtils::Status FileUtilsAndroid::getContents(const std::string& filename, Res
326337
return FileUtils::Status::ReadFailed;
327338
}
328339

340+
CCLOG("[sctest] file found OK", relativePath.c_str());
329341
return FileUtils::Status::OK;
330342
}
331343

0 commit comments

Comments
 (0)