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 

 

转载于:https://www.cnblogs.com/crazy-programmer/archive/2013/03/22/2974857.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值