cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.24k stars 7.06k forks source link

Lua project set a ccui.Text String crash on Android #17403

Open Dauch opened 7 years ago

Dauch commented 7 years ago

Steps to Reproduce:

local pText = ccui.Text:create()
pText:setString("")
pText:addTo(self)
DelayCall.delay(function()
    pText:removeFromParent()
    DelayCall.delay(function()
        pText:setString("")
    end, 1)
end, 1)

On windows it will prop a error(not crash):

invalid 'cobj' in function 'lua_cocos2dx_ui_Text_setString'

But on android it will crash, I think best way to is prop a error rather then crash.

xiayangqun commented 7 years ago

DelayCall.delay(function() pText:removeFromParent() DelayCall.delay(function() pText:setString("") end, 1) end, 1)

look at this code: you remove this node and after 1 second you want to setString age. when you remove it ,this node will free in native. So there will be a invaild 'cobj'

dumganhar commented 7 years ago

I guess the native object associated with pText was released since pText:removeFromParent was invoked.

@Dauch , yes, anyway, any lua invocations should not make game crash. For a quick fix, please don't use a binding object which was released.

Dauch commented 7 years ago

Yes I knew, but sometimes coder forgot to check,

Any lua invocations should not make game crash.

I think the engine should check a binding object is valid before use.