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 about 11 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
layerParent:addChild(node,0,9999)
@
When we wan to get this node and its extend attribute value somewhere, we can do as follow:
@
local child = layerParent:getChildByTag(9999)
print(child.extendValue1)
@
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

Status:Closed
Start date:2013-12-06
Priority:Normal
Due date:
Assignee:samuele3hu
% Done:

0%

Category:all
Target version:3.0-beta