cocos creater hot update restart causes crash

cocos creater hot update restart causes crash

knowledge points

  1. jsb_websocket_server.cpp socket used in the game
  2. Inspector_socket_server.cc V8 engine for remote debugging native socket server

demand background

  1. Game engine: cocos creater 2.4.3
  2. Calling cc.game.restart() after the hot update of the game causes a crash
  3. The online crash rate index rose sharply when the game was hotly updated

crash site

Accidentally got a model that can be displayed

The crash stack is as follows:

Please add a picture description

crash analysis

  1. According to the crash stack, it can be seen that jsb_websocket_server is called

  2. As a result of the breakpoint, you can see that the entry point of the crash is the method in the callback, as shown in the figure below

  3. Please add a picture description

  4. So it is speculated that after cc.game.restart(), the websocket is not released cleanly. After restarting, the wild pointer receives a callback, resulting in a crash

  5. Since we didn't use the websocket of cocos creator, we decided to remove the websocket

  6. The first step solution: Directly annotate the callback functions registered by jsb_websocket_server, and enter the game without crashing

  7. The second step solution: Check the source code to know whether to open the socket is controlled by a macro. As shown below

  8. Please add a picture description

  9. so we just need to add the macro definition and change USE_SOCKET to 0 as shown below

  10. Please add a picture description

Extended Thinking

  1. We didn't use websocket in our project, so we commented out websocket directly. Since the crash is websocket_server, in theory, if you need to use websocket, set USE_WEBSOCKET_SERVER to 0. You can also remember to check why the crash has not come yet. Those who have ideas can leave a message to exchange

  2. After removing the websocket, you can also remotely debug native, so I found out the principle of remote debugging again. code show as below:

  3. Please add a picture description

  4. From the figure above, we know that the remote debugging native function uses socket_setver in the V8 engine. What caused the crash was the websocket in the game engine

  5. You can also see it in the breakpoint running callback. When accessing the debug link, you can enter the breakpoint, you can try it yourself

At this point, the problem and solution of the crash caused by hot update game restart are over

Students who have questions are welcome to leave a message to discuss

Guess you like

Origin blog.csdn.net/qq_45504161/article/details/125809318