Exploration of unity3d exception reporting in webplayer Mode

Source: Internet
Author: User
Tags try catch

We know that unity3d runs in the sandbox environment in the release mode of webplayer. According to the official unity3d documentation, unmanaged DLL cannot be used in the webplayer mode. That is to say, the traditional C ++ game client generates the unmanaged DLL-dbghelp used by minidump. DLL, in. net can also be called using P/invokeMinidumpwritedumpBut it cannot be used in webplayer mode.

In webplyaer mode, how does one collect exception information when the unity3d client crashes?

Since we cannot use an unmanaged DLL or generate minidump, can we get the exception information? For example, the call stack information when an exception occurs, the source file and the corresponding row number.

We don't want to use try catch to include any client statement during execution, which can be a headache. You can recall the global exception capture function supported in. Net:

(1) Use the threadexception event of Application

Application.Threadexception + =New Threadexceptioneventhandler(Application_threadexception);

(2) Use the appdomain unhandledexception event

Appdomain.Currentdomain.Unhandledexception+ =NewUnhandledexceptioneventhandler(Currentdomain_unhandledexception);

However, from the practice results, unity3d does not support method 1, because the unity3dProgramThe application is not a winform application. The application is in the system. windows. the form namespace cannot be included. For method 2, the function is to capture unprocessed exceptions, but in practice, it is found that the compiled callback function is not called. In the editor Console window, the exception information is displayed, which means that the exception has been processed by other places (it should be in the unity3d Runtime Library ), this is also the depressing aspect of unity3d development in the "shell"-you cannot control the global, RuntimeCodeIt is uncontrollable for us.

So methods 1 and 2 are all ruined.

After reading the following document, we found that unity3d provides such a static function in the unityengine application class:

Public static voidRegisterlogcallback(Application. logcallbackHandler);

Its function is to register our callback function when unity3d executes the log. Let's look at it again.Application. logcallbackPrototype:

Public Delegate voidLogcallback(StringCondition,String
Stacktrace,LogtypeType);

You can obtain the required error or exception information based on the logtype. It should be noted that after the unity program is released, unity will still generate the log, in addition to its own exception or error log, as well as the Debug. Log called by developers themselves. Therefore, we can use the unity3d Log Mechanism to obtain the exception information. Generally, when we run it in the editor, the log information displayed in the console window is rich enough. The following is a test applet, in which an exception except 0 is intentionally generated:

InProcessexceptionreportYou can obtain the following information:


Note that stacktrace, as long as it is expanded at the end of \ n, is the information in the stack format. condition indicates that it is an exception. In this case, it is an exception except 0.

So far, as we only need to capture errors or exceptions, we need to filter them in the callback function.

After the exception information is obtained, it is reported. We will not repeat it here. We can communicate with the exception handling server to report the exception information. In fact, it would be best to get minidump. After all, the amount of information is different. I am very grateful to anyone who can provide the method!

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.