We are migrating issue tracker of Cocos2d-x Project to Github, please create new issue there. Thanks.
Lua gc mechanism will make the extended attributes of lua userdata disapper
Lua gc mechanism will make the extended attributes of lua userdata disapper
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.
Status: | Closed | |
---|---|---|
Start date: | 2013-12-06 | |
Priority: | Normal | |
Due date: | ||
Assignee: | samuele3hu | |
% Done: | 0% |
|
Category: | all | |
Target version: | 3.0-beta |