pthread 造成 CCScene::node(); 停止

pthread 造成 CCScene::node(); 停止
0.0 0


單步追進去,看是卡在CCScene *pRet = new CCScene();這行;還望高手指點,謝謝!

Sorry,I just saw the FAQ, so I post again…

I have a problem about using thread in Cocos2d-X, I create a thread by pthread_create() first,then create socket(),connect()…use SIGIO to get the socket’s r/w signal, store the data received from socket, and process the data in the thread;
It’s work find on the iOS simulator (iPad 5.1 simulator). but when I test on the iPad device, It will stopped on the code ‘CCScene scene = CCScene::node;’.I tried few times, remark the thread part the scene will work fine, or remark the SIGIO (sigfillset & sigaction) will work fine too….
I trace the code, found it’s stopped on ’CCScene
pRet = new CCScene();’, Please someone help me


Don’t invoke engine’s codes in a new thread.
It is not thread-safe.


Minggo Zhang wrote:

Don’t invoke engine’s codes in a new thread.
It is not thread-safe.

Dear Minggo…

Thank you for your reply…

I check my source code, and found I only use CCLog(); for debug, so I removed all the CCLog(); in the thread, but it’s still stopped while CCLayer::init(), so I try to remark the source code in my thread to find out which code make the Cocos2d-X holding…
and I found if I call socket’s send(); order than Cocos2d-X will stopped while CCLayer::init()……

what’s your suggestion for my situation? And what is the best way to create a socket Client application with Cocos2d-X engine you recommend ? Is there any sample code that I can study for this issue ?

Thanks again

Best Regards,

Atwood Yen


I think you can refer to CCTextureCache::addImageAsync().