When are Resources available to use?

I am having a strange problem. I’m not sure if it is to do with Cocos2d-x or OSX / iOS.

I am finding that sometimes the files in the Resources folder are not available to load in time when the application runs. For example, a texture or a json data file may not exist, but if I wait for a short time (or even just put a breakpoint in and then resume execution) then they will be there. I found that by waiting until after the main Scene’s init() function was called before I loaded my data, then it would be there in time, but on an iOS device it is still not ready.

I can’t see any other mention of this on the forum which makes me think I’m doing something weird. It seems like the file is either there or not, and should be available right away. Has anyone else seen this?

Extra information:

This is happening both using Cocos2d-x functions like Label::create(…) and Sprite::create(…) as well as with standard code like this:

    std::string fullPath = cocos2d::FileUtils::getInstance()->
        fullPathForFilename(path.c_str());
    
    std::ifstream t(fullPath);

I’m using Cocos2d-x 3.0. on OSX Mavericks, with XCode 5.1.1

see this, it might help. :smile:

Thanks for the tips, @pabitrapadhy, but I’m pretty sure that my problem is not related to those issues. It’s really weird that the assets are only missing sometimes, and that it appears to be time-related, ie they become available after a delay.

I’m cross posting this question over at Stack Overflow, since I’m not sure if it’s specific to Cocos2d-x:

http://stackoverflow.com/questions/24790691/xcode-ios-delay-before-resources-are-available

@Lee can you please let us know what are you testing your application on. ?
the emulator or an actual device.

if it is an actual device. let us know what is it. ?? :smile:

Hi, I eventually figured out that I had an initialisation problem, although I did find out that on OSX / iOS, the resources are not available until after applicationDidFinishLaunching() is called, which does answer the original question, (and was something I didn’t know.) The way Cocos2d-x is set up, it’s pretty hard to do anything before that anyway, at least for anything in the Cocos api.

@pabitrapadhy - Thanks for taking the time to help out.

yes all the resources are loaded once the applicationDidFinishLaunching() is called.

Oh you are most welcome @Lee

I am happy to help.
Happy Coding :smile: