Projects > cpp > Issues > Bug #3986

We are migrating issue tracker of Cocos2d-x Project to Github, please create new issue there. Thanks.

Create Issue on Github

CCHttpClient -- halts when called destroyInstance() and then created again. Cocos2d-x 2.1

Bug #3986 [Closed]
SPQR301 2014-02-10 15:53 . Updated over 8 years ago

Appears on iOS and Android.

  1. Create and use CCHttpClient:

    CCHttpRequest *request = new CCHttpRequest();
    request->setUrl(URL);
    request->setRequestType(CCHttpRequest::kHttpDownload);
    request->setResponseCallback(this, httpresponse_selector(UnitMapScene::downloadCompleted));
    request->setDownloadPath(destination);

    CCHttpClient *sharedClient = CCHttpClient::getInstance();
    sharedClient->setTimeoutForConnect(1);
    sharedClient->setTimeoutForRead(3600);
    sharedClient->send(request);

  2. destroy the instance when download is ready
    CCHttpClient *sharedClient = CCHttpClient::getInstance();
    sharedClient->destroyInstance();

  3. Do #1 again:
    Application freezes:
    EXC_BAD_ACCESS ( s_requestQueue is NULL)
    HttpClient.cpp line 462: s_requestQueue->addObject(request);

Version 2.1

SPQR301 2014-03-11 12:45

See pull request here: https://github.com/cocos2d/cocos2d-x/pull/5682

Change
this:

bool CCHttpClient::lazyInitThreadSemphore()
{
if (s_requestQueue != NULL) {
    return true;
} else {

    s_requestQueue = new CCArray();
    s_requestQueue->init();

    s_responseQueue = new CCArray();
    s_responseQueue->init();

    s_progressResponseQueue = new CCArray();
    s_progressResponseQueue->init();

    pthread_mutex_init(&s_requestQueueMutex, NULL);
    pthread_mutex_init(&s_responseQueueMutex, NULL);
    pthread_mutex_init(&s_progressResponseQueueMutex, NULL);

    pthread_mutex_init(&s_SleepMutex, NULL);
    pthread_cond_init(&s_SleepCondition, NULL);

    need_quit = false;

    pthread_create(&s_networkThread, NULL, networkThread, NULL);
    pthread_detach(s_networkThread); 
}

return true;
}

to this:

bool CCHttpClient::lazyInitThreadSemphore()
{
if (s_requestQueue != NULL) {
    return true;
} else {

    s_requestQueue = new CCArray();
    s_requestQueue->init();

    s_responseQueue = new CCArray();
    s_responseQueue->init();

    s_progressResponseQueue = new CCArray();
    s_progressResponseQueue->init();

    pthread_mutex_init(&s_requestQueueMutex, NULL);
    pthread_mutex_init(&s_responseQueueMutex, NULL);
    pthread_mutex_init(&s_progressResponseQueueMutex, NULL);

    pthread_mutex_init(&s_SleepMutex, NULL);
    pthread_cond_init(&s_SleepCondition, NULL);

    pthread_create(&s_networkThread, NULL, networkThread, NULL);
    pthread_detach(s_networkThread);

    need_quit = false;

}

return true;
}
walzer@cocos2d-x.org 2014-10-08 03:00

Redmine issue system is closed, we are using github issue system instead.

This issue was moved to https://github.com/cocos2d/cocos2d-x/issues/8337

Atom PDF

Status:Closed
Start date:2014-02-10
Priority:Low
Due date:
Assignee:-
% Done:

0%

Category:-
Target version:-