CCLabelTTF : will become a white rectangle
If you want invoke cocos2d-x function from a thread,It may be Crash.
I am working on a network game using cocos2dx with libcurl.
I created a CCLabelTTF on a CCLayer object.
Then I made a thread to request my java server using curl.
when a get response from the thread, I want to print a string on the CCLabelTTF.
I call setString , finally it become a white rectangle.
And I found that will only happen when I call it from a thread。
1、 We can not invoke any cocos2d-x function or from a thread.It is not thread-safe.
2、 every thread has its own openGL context if you add a texture in a thread which is not cocos2d-x's GLThread,
cocos2d-x won't get that texture because that texture belongs another thread.
So。。。
在线程中调用cocos2d-x 方法可能会导致程序没有规律的崩溃。
这次因为我在线程中调用了CCLabelTTF 的 setString() 导致了 变成了 白色的矩形。
get more :
http://www.cocos2d-x.org/boards/6/topics/9258