Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by x4000 · Jun 21, 2010 at 03:09 PM · erroroverflow

Global Error Logging and Overflow Checking?

So, I'm migrating projects from SlimDX and .NET 3.5, and there are two things that were insanely helpful on that side that I can't seem to find via a search of Answers, the Forum, or the Unity script documentation.

  • In Visual Studio projects, I can set a "Check for arithmetic overflow/underflow" option under Settings, Build, Advanced Build Settings. Is there a way to do something similar in Unity? If there are overflow errors I want to know about it, not have it just wrap around into the negatives.

  • In .NET 3.5, I had it set up so that the following code would log absolutely anything that went wrong in my game:

    [STAThread] static void Main() { Application.ThreadException += new System.Threading.ThreadExceptionEventHandler( Application_ThreadException ); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler( CurrentDomain_UnhandledException ); Application.Run( new Game() ); }

    private static void CurrentDomain_UnhandledException( object sender, UnhandledExceptionEventArgs e ) { File.AppendAllText( Configuration.GetLocalApplicationDataFolder() + "UnhandledErrors.txt", DateTime.Now + " (" + Game.GameVersionString + ")" + Environment.NewLine + "-----------------------------------" + "CurrentDomain_UnhandledException" + "-----------------------------------" + e.ExceptionObject.ToString() + Environment.NewLine ); AlertAndClose( (Exception)e.ExceptionObject ); }

    private static void Application_ThreadException( object sender, System.Threading.ThreadExceptionEventArgs e ) { File.AppendAllText( Configuration.GetLocalApplicationDataFolder() + "UnhandledErrors.txt", DateTime.Now + " (" + Game.GameVersionString + ")" + Environment.NewLine + "-----------------------------------" + "Application_ThreadException" + "-----------------------------------" + e.Exception.ToString() + Environment.NewLine ); AlertAndClose( e.Exception ); }

    Obviously there are a few custom calls in there, but those are just illustrative; the main thing is what happens in Main. Basically, that lets me get exceptions off the main thread, and off any other threads, and have them be logged in a super useful format. I'm even packaging the debug symbols along with, so it gives me a line number along with any errors. For public betas, that is super useful in particular.

    I know that Unity has the log under the _Data folder in windows (and something comparable on OSX), but that doesn't seem to log everything, it doesn't let me log custom messages to my knowledge, and it gets cleared out every time the player starts another game. I love that that Unity log exists, and it's not like I want to turn that off or anything, but I'd also love to be able to additionally do something more like the above in addition.

    Any thoughts?

    Comment
    Add comment
    10 |3000 characters needed characters left characters exceeded
    ▼
    • Viewable by all users
    • Viewable by moderators
    • Viewable by moderators and the original poster
    • Advanced visibility
    Viewable by all users

    3 Replies

    · Add your reply
    • Sort: 
    avatar image
    3
    Best Answer

    Answer by Ricardo · Jun 21, 2010 at 03:20 PM

    Have you reviewed Application.RegisterLogCallback ? While I haven't tested it myself, it would seem to be exactly what you need - you can use it to register your own callback function and then from it log by whatever method you desire (say, log4net).

    Comment
    Add comment · Show 3 · Share
    10 |3000 characters needed characters left characters exceeded
    ▼
    • Viewable by all users
    • Viewable by moderators
    • Viewable by moderators and the original poster
    • Advanced visibility
    Viewable by all users
    avatar image x4000 · Jun 21, 2010 at 07:55 PM 0
    Share

    Okay, this is perfect. Thanks! After getting around that bug mentioned in the other thread, this does just what I want. Very helpful!

    avatar image Jackmawer · Apr 09, 2015 at 04:22 PM 0
    Share

    The link you provide no longer works. In the interest of helping googlers, you can use this link to visit the page.

    avatar image Shabick · Jan 28, 2016 at 12:26 AM 0
    Share

    Seems the new function is Application.LogCallback for anyone viewing this now...

    avatar image
    2

    Answer by Mike 3 · Jun 21, 2010 at 03:18 PM

    Regarding overflows and underflows:

    You can use the checked and unchecked keywords to change the behaviour at a block level. It may not be the same as application level settings, but it's pretty much the only way it'll work with unity

    About the exception handling:

    You may be able to get away with adding your functions to the same events that you do in main. This won't catch native exceptions though, and not much can be done about that

    You can then pump your exceptions to your own log file (System.IO.File.* perhaps) if you prefer not to use the output.log provided by Unity

    Comment
    Add comment · Show 2 · Share
    10 |3000 characters needed characters left characters exceeded
    ▼
    • Viewable by all users
    • Viewable by moderators
    • Viewable by moderators and the original poster
    • Advanced visibility
    Viewable by all users
    avatar image x4000 · Jun 21, 2010 at 07:54 PM 0
    Share

    Okay, so this is pretty cool overall, thanks for the link there. I've been experimenting around with this (adding int.$$anonymous$$axValue to integers at runtime at various points), and the badnews is that this checked keyword is not stepping into the various methods. It works for a given code block and all the sub-blocks inside it (so inside loops, etc), but any method calls that are made don't inherit the checked property. Thinking about this, that makes sense for API purposes where that might cause unexpected crashes of a third party API, which is a bummer.

    avatar image x4000 · Jun 21, 2010 at 07:54 PM 0
    Share

    It seems like if there was a way to set this for the current AppDomain that would be the ideal solution (that's essentially what the compiler flag does, assu$$anonymous$$g one AppDomain in your executable), but I don't know a setting for that.

    avatar image
    0

    Answer by ybaklaci · Jan 08, 2016 at 08:23 PM

    Check Reporter plugin. It stores all of your logs (including error logs and stack trace) and sends a well-formated email with screen shot attached. Also it can be used in release mode.

    Comment
    Add comment · Share
    10 |3000 characters needed characters left characters exceeded
    ▼
    • Viewable by all users
    • Viewable by moderators
    • Viewable by moderators and the original poster
    • Advanced visibility
    Viewable by all users

    Your answer

    Hint: You can notify a user about this post by typing @username

    Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

    Follow this Question

    Answers Answers and Comments

    3 People are following this question.

    avatar image avatar image avatar image

    Related Questions

    Fatal error! System out of memory! Unity 3D 1 Answer

    object reference not set to an instance of an object 3 Answers

    unaxpected char: 0xaD 1 Answer

    end of line error 1 Answer

    Unity 4.3 with Xcode 5.0.2 build errors 1 Answer


    Enterprise
    Social Q&A

    Social
    Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

    Footer

    • Purchase
      • Products
      • Subscription
      • Asset Store
      • Unity Gear
      • Resellers
    • Education
      • Students
      • Educators
      • Certification
      • Learn
      • Center of Excellence
    • Download
      • Unity
      • Beta Program
    • Unity Labs
      • Labs
      • Publications
    • Resources
      • Learn platform
      • Community
      • Documentation
      • Unity QA
      • FAQ
      • Services Status
      • Connect
    • About Unity
      • About Us
      • Blog
      • Events
      • Careers
      • Contact
      • Press
      • Partners
      • Affiliates
      • Security
    Copyright © 2020 Unity Technologies
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell My Personal Information
    • Cookies Settings
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Explore
    • Topics
    • Questions
    • Users
    • Badges