the size of bytes read from jpg image is wrong when using CCImage::initWithImageFileThreadSafe(...) in a separate thread


#1

i need to load images in a separate thread. this code i used is copied from the function loadImage in CCTextureCache.cpp,
@ @ // generate image@
@ CCImage *pImage = new CCImage();@
@ if (pImage && !pImage->initWithImageFileThreadSafe(filename, imageType))@
@ {@
@ CC_SAFE_RELEASE(pImage);@
@ CCLOG (“can not load %s”, filename);@
@ continue;@
@ }@
everything is OK when i run it on iphone4. But when i run it on android device, it reports an error “cocos2d-x debug info(24717): Assert failed: the file size is wrong”, i find the code generate this error in function ZipFile::getFileData in cocos2dx/support/zip_support/ZipUtils.cpp. i print the nSize and fileInfo.uncompressed_size, nSize is 81920, fileInfo.uncompressed_size is 113794 which is right. Can anyone give me some infomation about this error? Thanks!


#2

anyone who has thoughts of this problem?


#3

finally i find the problem, CCImage::initWithImageFileThreadSafe is not thread safe if you use more than 1 thread on android because it uses ZipUtil::getFileData. i have to say the implementation of CCImage::initWithImageFileThreadSafe is not completed. you can find the discussion https://github.com/cocos2d/cocos2d-x/pull/1933.