Projects > cpp > Issues > Bug #3353

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

Create Issue on Github

Lua gc mechanism will make the extended attributes of lua userdata disapper

Bug #3353 [Closed]
samuele3hu 2013-12-06 06:13 . Updated over 8 years ago
samuele3hu 2013-12-06 06:31

When we create a node child for a layer and extend some attributes value,we can do as follow:
local node = cc.Node:create()
node.extendValue1 = 10000
When we wan to get this node and its extend attribute value somewhere, we can do as follow:
local child = layerParent:getChildByTag(9999)
Sometimes we will get 10000,and sometimes we will get nil. Because the lua gc event collect the node value,so when we call getChildByTag,it create a new usedata and the extend attribute value is nil.

To avoid the Object userdata to gc collect, we add the Object data to a global table to keep refrence, and when the destructor of releated object called,the refrence will be removed from this global table.In this way, we can use extended userdata attributes trustingly.

zhangxm 2013-12-30 05:56
  • Status changed from New to Closed

Atom PDF

Start date:2013-12-06
Due date:
% Done:


Target version:3.0-beta