{"action":"created","issue":{"url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/13072","labels_url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/13072/labels{/name}","comments_url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/13072/comments","events_url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/13072/events","html_url":"https://github.com/cocos2d/cocos2d-x/issues/13072","id":97841397,"number":13072,"title":"3.x 通过tolua自动导出到lua的C++函数异常检查的问题（原谅我无法reopen，很重要所以再次提出）","user":{"login":"c3076802","id":3726167,"avatar_url":"https://avatars.githubusercontent.com/u/3726167?v=3","gravatar_id":"","url":"https://api.github.com/users/c3076802","html_url":"https://github.com/c3076802","followers_url":"https://api.github.com/users/c3076802/followers","following_url":"https://api.github.com/users/c3076802/following{/other_user}","gists_url":"https://api.github.com/users/c3076802/gists{/gist_id}","starred_url":"https://api.github.com/users/c3076802/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/c3076802/subscriptions","organizations_url":"https://api.github.com/users/c3076802/orgs","repos_url":"https://api.github.com/users/c3076802/repos","events_url":"https://api.github.com/users/c3076802/events{/privacy}","received_events_url":"https://api.github.com/users/c3076802/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"dualface","id":62318,"avatar_url":"https://avatars.githubusercontent.com/u/62318?v=3","gravatar_id":"","url":"https://api.github.com/users/dualface","html_url":"https://github.com/dualface","followers_url":"https://api.github.com/users/dualface/followers","following_url":"https://api.github.com/users/dualface/following{/other_user}","gists_url":"https://api.github.com/users/dualface/gists{/gist_id}","starred_url":"https://api.github.com/users/dualface/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dualface/subscriptions","organizations_url":"https://api.github.com/users/dualface/orgs","repos_url":"https://api.github.com/users/dualface/repos","events_url":"https://api.github.com/users/dualface/events{/privacy}","received_events_url":"https://api.github.com/users/dualface/received_events","type":"User","site_admin":false},"milestone":null,"comments":10,"created_at":"2015-07-29T02:14:31Z","updated_at":"2015-08-05T02:08:42Z","closed_at":null,"body":"\tint lua_cocos2dx_Node_setCascadeOpacityEnabled(lua_State* tolua_S)\r\n\t{\r\n\t\tint argc = 0;\r\n\t\tcocos2d::Node* cobj = nullptr;\r\n\t\tbool ok  = true;\r\n\r\n\t#if COCOS2D_DEBUG >= 1\r\n\t\ttolua_Error tolua_err;\r\n\t#endif\r\n\r\n\r\n\t#if COCOS2D_DEBUG >= 1\r\n\t\tif (!tolua_isusertype(tolua_S,1,\"cc.Node\",0,&tolua_err)) goto tolua_lerror;\r\n\t#endif\r\n\r\n\t\tcobj = (cocos2d::Node*)tolua_tousertype(tolua_S,1,0);\r\n\r\n\t#if COCOS2D_DEBUG >= 1\r\n\t\tif (!cobj) \r\n\t\t{\r\n\t\t\ttolua_error(tolua_S,\"invalid 'cobj' in function 'lua_cocos2dx_Node_setCascadeOpacityEnabled'\", nullptr);\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t#endif\r\n\r\n\t\targc = lua_gettop(tolua_S)-1;\r\n\t\tif (argc == 1) \r\n\t\t{\r\n\t\t\tbool arg0;\r\n\r\n\t\t\tok &= luaval_to_boolean(tolua_S, 2,&arg0, \"cc.Node:setCascadeOpacityEnabled\");\r\n\t\t\tif(!ok)\r\n\t\t\t{\r\n\t\t\t\ttolua_error(tolua_S,\"invalid arguments in function 'lua_cocos2dx_Node_setCascadeOpacityEnabled'\", nullptr);\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t\tcobj->setCascadeOpacityEnabled(arg0);\r\n\t\t\tlua_settop(tolua_S, 1);\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t\tluaL_error(tolua_S, \"%s has wrong number of arguments: %d, was expecting %d \\n\", \"cc.Node:setCascadeOpacityEnabled\",argc, 1);\r\n\t\treturn 0;\r\n\r\n\t#if COCOS2D_DEBUG >= 1\r\n\t\ttolua_lerror:\r\n\t\ttolua_error(tolua_S,\"#ferror in function 'lua_cocos2dx_Node_setCascadeOpacityEnabled'.\",&tolua_err);\r\n\t#endif\r\n\r\n\t\treturn 0;\r\n\t}\r\n\r\n比如以上代码，如果COCOS2D_DEBUG 不是>=1的话，if (!cobj) 这句就不会执行，在运行中是会有cobj == null的情况的，比如说\r\n1. 脚本使用了一个Node，将其放在一个callback里面执行（并没有retain）\r\n2. callback还没执行之前，其他脚本代码删除了Node\r\n3. 在lua的注册表就删除了该Node的关联\r\n4. callback调用，cobj = (cocos2d::Ref*)tolua_tousertype(tolua_S,1,0); cobj返回null\r\n5. 崩溃\r\n这个脚本程序员很常见的错误，如果一个不小心，release版本就不明不白的就挂了。\r\n我宁愿要一个slow and safe的运行环境，所以我才请求，在lua自动导出的文件(auto)里面，关于lua异常检查的开关宏不要用COCOS2D_DEBUG来处理，\r\n因为COCOS2D_DEBUG关联了整个COCOS的DEBUG模式，我需要的是可开关是否做lua C++函数的异常检查的宏，甚至完全启用lua C++函数异常检查也可以。\r\n@pandamicro"},"comment":{"url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/comments/127819607","html_url":"https://github.com/cocos2d/cocos2d-x/issues/13072#issuecomment-127819607","issue_url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/13072","id":127819607,"user":{"login":"zilongshanren","id":785541,"avatar_url":"https://avatars.githubusercontent.com/u/785541?v=3","gravatar_id":"","url":"https://api.github.com/users/zilongshanren","html_url":"https://github.com/zilongshanren","followers_url":"https://api.github.com/users/zilongshanren/followers","following_url":"https://api.github.com/users/zilongshanren/following{/other_user}","gists_url":"https://api.github.com/users/zilongshanren/gists{/gist_id}","starred_url":"https://api.github.com/users/zilongshanren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zilongshanren/subscriptions","organizations_url":"https://api.github.com/users/zilongshanren/orgs","repos_url":"https://api.github.com/users/zilongshanren/repos","events_url":"https://api.github.com/users/zilongshanren/events{/privacy}","received_events_url":"https://api.github.com/users/zilongshanren/received_events","type":"User","site_admin":false},"created_at":"2015-08-05T02:08:42Z","updated_at":"2015-08-05T02:08:42Z","body":"@c3076802 Could you send a PR?\r\nThanks."}}