About cocos2dx program BUG debugging Solution

Source: Internet
Author: User

Let's talk about debugging of mobile game development today. I have to say that, compared with PC platform games and software development, it is much more difficult to develop games and software on mobile phones. There are many reasons for this. For example, the development environment is complicated, and the tools and software are not user-friendly.

The emergence of cocos2dx solves a big problem because it is a cross-platform software development environment that is relatively friendly for windows and more familiar to Chinese programmers. In this way, you can conduct daily development and debugging in windows, and then perform a small amount of processing when releasing it to other platforms.

The debugging of cocos2dx is similar to that of client games in windows. It can be printed in the background window, or it can be traced directly by hitting a breakpoint in. Relatively easy. The only thing that needs to be optimized is to export the printed logs in the background to facilitate log analysis.

However, after the windows environment is OK and you need to release it to the Android platform, it will be a little troublesome and smooth. Once a problem occurs during the running process, debugging is quite troublesome. The simulator is full of snails, and the support of Esclipe itself is not powerful enough. Sometimes an error may be reported by a script, but it may take a long time to discover the problem. If an error occurs on the real machine, it is even worse to track the problem. You also need to use the USB debugging function. Today's main topic is to address this situation and provide several good methods to facilitate game development.

1. Optimization of log printing in the background.

In windows, the background Log Viewing function is available, but you may find a problem. There is a limit on the number of lines displayed in the background, and you will not be able to see the number of lines after the limit is exceeded, however, cocos2dx outputs a lot. What should I do? The solution is to output the log file. After outputting the content displayed in the background, we can analyze the log file directly. The following provides the lua solution code, which can be transformed by C ++.

First, encapsulate the file processing function of lua, which is relatively simple, and the subsequent methods may also need to be used.

-- File. lua -- defines the lua File Operation Method -- open the file: parameter (file name, open mode), returns the file handle or nilfunction openFile (filename, mode) local f = io. open (filename, mode) if f thenreturn felsereturn nilendend -- read all content of the file: parameter (file handle), returns a stringfunction readAllFile (f) return f: read ("* all ") end -- read a row of file content: parameter (file handle), returns a stringfunction readLineFile (f) return f: read ("* line") end -- Write File Content: parameter (file handle, string) function writeFile (f ,...) local arg = {...} f: write (unpack (arg) end -- close the file, parameter (file handle () function closeFile (f) f: close () end
Then, we need to rewrite the print function and the cclog function to output the content to the file.

local print_raw = print-- printprint = function(...)    require "base.file"    print_raw(string.format(...))    local file = openFile("client.log", "a")    if file thenwriteFile(file, string.format(...).."\n")closeFile(file)    endend-- cclogcclog = function(...)    print(string.format(...))end-- for CCLuaEngine tracebackfunction __G__TRACKBACK__(msg)    print("----------------------------------------")    print("LUA ERROR: " .. tostring(msg) .. "\n")    print(debug.traceback())    print("----------------------------------------")end
In this way, all printed information in lua will be output to the log file for analysis.

2. The above method allows us to share logs. Is there any better way? If I am running on an Android phone, is it inconvenient for me to view logs?

So let's go further. Didn't we output logs to files? Is it more convenient for us to view logs directly in the game? So our idea is to write a log display interface in the game, and then read the log file content in a row so that it is displayed in a RichText control. Is this more convenient? I have no time to write this method for the moment, but it is certainly no problem. I have time to write it and then add the code.

3. method 2 is able to see logs in a timely manner. We can also use a larger method. We can create a log server and send the client to the log server when outputting logs, in this way, real machine testing is very convenient and similar to development in windows, but this solution is a bit heavy. You can use the second point.
Well, the three solutions recommended above should be able to solve most of the debugging problems, and no longer need to start troublesome simulators to view logs.

Reprinted please indicate the source: curtain roll west wind column (http://blog.csdn.net/ljxfblog)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.