cURL to CCScale9Sprite works on iOS not on Android

cURL to CCScale9Sprite works on iOS not on Android
0.0 0


I have a function that saves an image from a website, and then loads it into a CCScale9Sprite. This function works great on iOS and fails on Android, the only error I get is:

05-14 16:01:02.857: D/cocos2d-x debug info(14697): dlButton save dir = /data/data/com.nds.sprite9fail/files/dlButton.jpeg
05-14 16:01:02.864: D/cocos2d-x debug info(14697): … curl performed (file != NULL)
05-14 16:01:02.864: D/cocos2d-x debug info(14697): … curl cleaned
05-14 16:01:02.864: D/cocos2d-x debug info(14697): … created regular CCSprite
05-14 16:01:02.864: A/libc(14697): Fatal signal 11 (SIGSEGV) at 0x00000038 (code=1), thread 14711 (Thread-779)

I believe it has to do with how the Scale9Sprite loads the asset because it when I run the code, it looks like the regular CCSprite does successfully load (the CCLog shows).

I am an absolute novice to Android development, so any pointers would be greatly appreciated.

I made a sample project, attached are the HelloWorld files to exhibit the issue, but for quickness, here is the function:

void HelloWorld::onEnter() {

    std::string dir = CCFileUtils::sharedFileUtils()->getWritablePath();
    if (dir.size() > 0 && dir[dir.size() - 1] != '/') dir.append("/");

    CCLog("dlButton save dir = %s", dir.c_str());

    CURL *curl = curl_easy_init();
    if (curl) {
        // Open up writable temp graphic.
        FILE *file = fopen(dir.c_str(), "wb");

        CCString* url = CCString::createWithFormat("");

        // Generate URL for proper image size.
        // char url[64];
        // sprintf(url, "", (int)size.width, (int)size.height);

        // Allow follow location for "302 File Found" redirect.
        curl_easy_setopt(curl, CURLOPT_URL, url->getCString());
        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_write);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);

        // Write the image to the file.

        CCLog("... curl performed (file %s NULL)", (file == NULL ? "==" : "!="));



        CCLog("... curl cleaned");

        CCSprite* testSprite = CCSprite::create(dir.c_str());

        CCLog("... created regular CCSprite");

        CCScale9Sprite* newSprite = CCScale9Sprite::create(dir.c_str()); // TODO: this crashes on android!?

        CCLog("... created CCScale9Sprite");

        CCSize size = CCDirector::sharedDirector()->getWinSize();
        testSprite->setPosition( ccp(size.width/4, size.height/2) );
        this->addChild(testSprite, 0);

        CCSize oSize = newSprite->getOriginalSize();
        newSprite->setCapInsets(CCRect(0, 0, oSize.width, oSize.height));

        newSprite->setPosition( ccp(size.width*3/4, size.height/2) );
        this->addChild(newSprite, 0);

        CCLog("... sprites added");

        // */
    } else {
        // failed to generate curl

    CCLog("... curl completely done");
} (3.0 KB)


CLOSED: I hadn’t added the appropriate permissions to the Manifest, stupid me.