[Fixed] addImageSync fails to return a callback for few images on Android

I have a splash screen where I am loading all assets (png files) asynchronously. Once I get callbacks from all those assets, I switch the scene to main menu. This logic works fine on windows and IOS but for some reason few images do not return callback on android phone.

I have seen a similar issue here although the bug occurs for me always unlike the following issue

Can anyone explain whats going wrong ?

There is race condition () in addImageAsync. Below my workaround:" Do not use callback check in loop if really loaded" Could you create issue in github for this problem? Could you attach source code how to reproduce it in 100% on android?

auto a1 = cocos2d::CallFunc::create(this {
if (cocos2d::Director::getInstance()->getTextureCache()->getTextureForKey(name) != nullptr)
{
Loaded();
this->stopAction(loadImageAsyncAction);
}
});
auto seq = cocos2d::Sequence::create(a1, cocos2d::DelayTime::create(0.1f), nullptr);
loadImageAsyncAction = this->runAction(cocos2d::RepeatForever::create(seq));

1 Like

Unfortunately, I cant attach my source code here however I will explain better how I have coded it.
I call a method that is made up of several calls to addImageAsync sequentially.

Director::getInstance()->getTextureCache()->addImageAsync(“image1.png”, CC_CALLBACK_1(Iterface::callback, observer));
Director::getInstance()->getTextureCache()->addImageAsync(“image2.png”, CC_CALLBACK_1(Iterface::callback, observer));
Director::getInstance()->getTextureCache()->addImageAsync(“image3.png”, CC_CALLBACK_1(Iterface::callback, observer));

and so on.

If I understand you correctly, sequential calls to addImageAsync will result in a deadlock.If so, in which better way can I achieve the same result (pre-loading multiple assets at same time)

addImageAsync will work when you will not use callback(or any other async methods) Just use addImageAsync (with empty callback) and use I.e action (code from my first response) to check that images are loaded.

I used an update() to check if the callbacks are fired, go to the main scene if so, and go to the main scene after 5 seconds in any case.
But your idea is better.

I fixed the issue using the solution mentioned in this link

Thank you for info!