CCSprite from URL

CCSprite from URL
0.0 0


Hi, I’m trying to load a CCSprite from Facebook server. But when it loads, it appear a black image. And I don’t know why. I think that CURL buffer it’s 0 I leave my code. I don’t know if it’s an easy way to do it.

Edit: I already try on the main thread, and also it’s black

Note: I’m running it on a pthread.

//called at the end of init
pthread_t tid1;
    pthread_create(&tid1, NULL, &loadSync, this);

struct MemoryStruct {
    char *memory;
    size_t size;

static size_t
WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) {
    size_t realsize = size * nmemb;
    struct MemoryStruct *mem = (struct MemoryStruct *)userp;
    mem->memory = (char *)realloc(mem->memory, mem->size + realsize + 1);
    if (mem->memory == NULL) {
        /* out of memory! */
        printf("not enough memory (realloc returned NULL)\n");
    memcpy(&(mem->memory[mem->size]), contents, realsize);
    mem->size += realsize;
    mem->memory[mem->size] = 0;
    return realsize;

//This class it's called helpBlock
static void *loadSync(void *args) {
    helpBlock *thiz = (helpBlock*)args;

    CURL *curl_handle;
    struct MemoryStruct chunk;

    /* will be grown as needed by the realloc above /
     chunk.size = 0;    / no data at this point */
    chunk.memory = (char*)malloc(1);
    chunk.size = 0;

    /* init the curl session */
    curl_handle = curl_easy_init();
    /* specify URL to get */
    curl_easy_setopt(curl_handle, CURLOPT_URL, "");
    /* send all data to this function  */
    curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
    /* we pass our 'chunk' struct to the callback function */
    curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);
    /* some servers don't like requests that are made without a user-agent
     field, so we provide one */
    curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
    /* get it! */
    /* cleanup curl stuff */

    CCLog("%s - %d", chunk.memory, chunk.size);
    CCImage* img = new CCImage;
    img->initWithImageData((void*)chunk.memory, (long)chunk.size, CCImage::kFmtPng);
    cocos2d::CCTexture2D* texture = new cocos2d::CCTexture2D();


    /* we're done with libcurl, so clean it up */

    return NULL;