fix crash when back to parent test case

This commit is contained in:
minggo 2016-05-10 17:55:36 +08:00
parent 04f52d0e21
commit b2a592ce36
2 changed files with 11 additions and 2 deletions

View File

@ -268,7 +268,8 @@ WebSocketCloseTest::WebSocketCloseTest()
if (!_wsiTest->init(*this, "ws://echo.websocket.org"))
{
CC_SAFE_DELETE(_wsiTest);
delete _wsiTest;
_wsiTest = nullptr;
}
auto closeItem = MenuItemImage::create(s_pathClose, s_pathClose, [](Ref* sender){
@ -289,6 +290,12 @@ WebSocketCloseTest::WebSocketCloseTest()
addChild(notifyLabel, 1);
}
WebSocketCloseTest::~WebSocketCloseTest()
{
if (_wsiTest)
_wsiTest->close();
}
// Delegate methods
void WebSocketCloseTest::onOpen(network::WebSocket* ws)
{
@ -303,7 +310,8 @@ void WebSocketCloseTest::onMessage(network::WebSocket* ws, const network::WebSoc
void WebSocketCloseTest::onClose(network::WebSocket* ws)
{
log("websocket (%p) closed.", ws);
CC_SAFE_DELETE(ws);
delete ws;
_wsiTest = nullptr;
}
void WebSocketCloseTest::onError(network::WebSocket* ws, const network::WebSocket::ErrorCode& error)

View File

@ -64,6 +64,7 @@ public:
virtual void onError(cocos2d::network::WebSocket* ws, const cocos2d::network::WebSocket::ErrorCode& error)override;
WebSocketCloseTest();
~WebSocketCloseTest();
virtual std::string title() const override { return "WebSocket close by resetDirector event Test"; }
std::string subtitle() const override { return "Click close button, Program should close without crash."; }