{"action":"created","issue":{"url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/15898","repository_url":"https://api.github.com/repos/cocos2d/cocos2d-x","labels_url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/15898/labels{/name}","comments_url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/15898/comments","events_url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/15898/events","html_url":"https://github.com/cocos2d/cocos2d-x/issues/15898","id":161405480,"number":15898,"title":"cocos2d-js 3.9 render的时候发生crash","user":{"login":"iNeverSleeeeep","id":8469299,"avatar_url":"https://avatars.githubusercontent.com/u/8469299?v=3","gravatar_id":"","url":"https://api.github.com/users/iNeverSleeeeep","html_url":"https://github.com/iNeverSleeeeep","followers_url":"https://api.github.com/users/iNeverSleeeeep/followers","following_url":"https://api.github.com/users/iNeverSleeeeep/following{/other_user}","gists_url":"https://api.github.com/users/iNeverSleeeeep/gists{/gist_id}","starred_url":"https://api.github.com/users/iNeverSleeeeep/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iNeverSleeeeep/subscriptions","organizations_url":"https://api.github.com/users/iNeverSleeeeep/orgs","repos_url":"https://api.github.com/users/iNeverSleeeeep/repos","events_url":"https://api.github.com/users/iNeverSleeeeep/events{/privacy}","received_events_url":"https://api.github.com/users/iNeverSleeeeep/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":11,"created_at":"2016-06-21T10:50:18Z","updated_at":"2016-06-24T02:00:05Z","closed_at":null,"body":"发生crash的直接原因是我使用的一个renderTexture在delete后依然会被绘制。\r\n下面写一下我猜测的原因：\r\n我的项目使用websocket做网络连接，在收到某一个消息后我会调用renderTexture.removeFromParent();\r\n有没有这种可能，在某一帧的update里面我调用了renderTexture.beginWithClear()，在这之后收到了上述消息的回调，将renderTexture delete，但是那个CustomCommand依然还在renderQ里面，所以导致了crash。\r\n以上是我的猜测，若不可能发生，我再查查还有没有其他的可能。"},"comment":{"url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/comments/228237386","html_url":"https://github.com/cocos2d/cocos2d-x/issues/15898#issuecomment-228237386","issue_url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/15898","id":228237386,"user":{"login":"iNeverSleeeeep","id":8469299,"avatar_url":"https://avatars.githubusercontent.com/u/8469299?v=3","gravatar_id":"","url":"https://api.github.com/users/iNeverSleeeeep","html_url":"https://github.com/iNeverSleeeeep","followers_url":"https://api.github.com/users/iNeverSleeeeep/followers","following_url":"https://api.github.com/users/iNeverSleeeeep/following{/other_user}","gists_url":"https://api.github.com/users/iNeverSleeeeep/gists{/gist_id}","starred_url":"https://api.github.com/users/iNeverSleeeeep/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iNeverSleeeeep/subscriptions","organizations_url":"https://api.github.com/users/iNeverSleeeeep/orgs","repos_url":"https://api.github.com/users/iNeverSleeeeep/repos","events_url":"https://api.github.com/users/iNeverSleeeeep/events{/privacy}","received_events_url":"https://api.github.com/users/iNeverSleeeeep/received_events","type":"User","site_admin":false},"created_at":"2016-06-24T02:00:04Z","updated_at":"2016-06-24T02:00:04Z","body":"I just use the cocos2d-js APIs, and I think it's better for you to just take a look at the websocket codes.\r\nAny way, i will post some codes down here.\r\n```\r\n// websocket thread receive msg\r\nint WebSocket::onSocketCallback(struct lws_context *ctx,\r\n                     struct lws *wsi,\r\n                     int reason,\r\n                     void *user, void *in, ssize_t len) {\r\n    //  codes\r\n     _wsHelper->sendMessageToUIThread(msg);\r\n    // codes\r\n}\r\n\r\n// websocket thread push queue\r\nvoid WsThreadHelper::sendMessageToUIThread(WsMessage *msg)\r\n{\r\n    std::lock_guard<std::mutex> lk(_UIWsMessageQueueMutex);\r\n    _UIWsMessageQueue->push_back(msg);\r\n}\r\n\r\n// ui thread update handle the msg\r\nvoid WsThreadHelper::update(float dt)\r\n{\r\n    /* Avoid locking if, in most cases, the queue is empty. This could be a little faster.\r\n    size() is not thread-safe, it might return a strange value, but it should be OK in our scenario.\r\n    */\r\n    if (0 == _UIWsMessageQueue->size()) \r\n        return;\t\r\n\r\n    // Returns quickly if no message\r\n    _UIWsMessageQueueMutex.lock();\r\n\r\n    if (0 == _UIWsMessageQueue->size())\r\n    {\r\n        _UIWsMessageQueueMutex.unlock();\r\n        return;\r\n    }\r\n    \r\n    // Gets message\r\n    // Process all messages in the queue, in case it's piling up faster than being processed\r\n    std::list<WsMessage*> messages;\r\n    while (!_UIWsMessageQueue->empty()) {\r\n        messages.push_back(_UIWsMessageQueue->front());\r\n        _UIWsMessageQueue->pop_front();\r\n    }\r\n\r\n    _UIWsMessageQueueMutex.unlock();\r\n    \r\n    for (auto msg : messages) {\r\n        if (_ws)\r\n        {\r\n            _ws->onUIThreadReceiveMessage(msg); //----------->here\r\n        }\r\n        CC_SAFE_DELETE(msg);\r\n    }\r\n}\r\n\r\n// ui thread delegate is JSB_WebSocketDelegate, and WebSocketDelegate will invoke js codes;\r\nvoid WebSocket::onUIThreadReceiveMessage(WsMessage* msg)\r\n{\r\n    switch (msg->what) {\r\n        case WS_MSG_TO_UITHREAD_OPEN:\r\n            {\r\n                _delegate->onOpen(this);\r\n            }\r\n            break;\r\n        case WS_MSG_TO_UITHREAD_MESSAGE:\r\n            {\r\n                Data* data = (Data*)msg->obj;\r\n                _delegate->onMessage(this, *data);\r\n                CC_SAFE_DELETE_ARRAY(data->bytes);\r\n                CC_SAFE_DELETE(data);\r\n            }\r\n            break;\r\n        case WS_MSG_TO_UITHREAD_CLOSE:\r\n            {\r\n                //Waiting for the subThread safety exit\r\n                _wsHelper->joinSubThread();\r\n                _delegate->onClose(this);\r\n            }\r\n            break;\r\n        case WS_MSG_TO_UITHREAD_ERROR:\r\n            {\r\n                // FIXME: The exact error needs to be checked.\r\n                WebSocket::ErrorCode err = ErrorCode::CONNECTION_FAILURE;\r\n                _delegate->onError(this, err);\r\n            }\r\n            break;\r\n        default:\r\n            break;\r\n    }\r\n}\r\n\r\n```\r\nI don't know how to make it more clear.\r\nMaybe call renderTexture.beginWithClear() in update is wrong, although I don't think of it.\r\n\r\n"}}
{"actor":{"display_login":"iNeverSleeeeep"}}