Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Will it work in new Mono? 1) DebuggerHiddenAttribute 2) name of variable when NullReferenceException

Discussion in 'Experimental Scripting Previews' started by Deni35, Dec 13, 2016.

  1. Deni35

    Deni35

    Joined:
    Jul 10, 2012
    Posts:
    43
    DebuggerHidden attribute allow you to skip frame in callstack.
    But for some reason it does not work in Unity.
    https://feedback.unity3d.com/suggestions/debug-console-callstack-skip-par

    This is a convenient feature in some cases. For example:
    Code (CSharp):
    1.  
    2. public static T RequireComponent<T>(this Component comp) where T : Component {
    3.    T result = comp.GetComponent<T>();
    4.    if(result == null) Debug.LogErrorFormat( comp, "Object '{0}' hasn't component '{1}'", comp.gameObject.name, typeof( T ).Name ); // I want callstack points to my RequireComponent instead of LogErrorFormat.
    5.    return result;
    6. }
    Will it work in new Mono?


    And second question.
    Now when I'm getting NullReferenceException I can't see name of reference.
    It is very inconvenient and time-consuming.
    So, will it work?
     
    Last edited: Dec 13, 2016
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,936
    I'm not sure about support for the DebuggerHidden attribute with Unity and the new Mono, I'll check on that and report back though.

    The issue with a NullReferenceException sounds like a bug. Can you submit a bug report for that issue?
     
  3. Deni35

    Deni35

    Joined:
    Jul 10, 2012
    Posts:
    43
    it has always been so.

    Code (CSharp):
    1.  
    2. Object myVar = null;
    3. Debug.LogError( myVar.name );
    4.  
    NullReferenceException: Object reference not set to an instance of an object
    MyScript.Awake () (at Assets/MyScript:10)
    ...

    Where is name 'myVar' of null reference?


    if I have code:
    Code (CSharp):
    1.  
    2. if( ref1.ref2.ref3.num == 0 ) ref4.ref5.ref6.num = 1;
    3.  
    It is difficult to understand what the reference was null.
     
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,936
    Ahh, ok. This is not a new bug then. Thinking more about this, I'm not sure there is much more we can do here. The name of the variable in C# code is probably not available to the runtime.
     
  5. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,936
    For the DebuggerHidden attribute, it looks like something we probably can support. We're getting the managed debugger working with the Mono preview build now, so we will try this.
     
    Deni35 and alexzzzz like this.
  6. Deni35

    Deni35

    Joined:
    Jul 10, 2012
    Posts:
    43
    Cool. I will wait for this.
     
  7. robin-fischer

    robin-fischer

    Joined:
    Aug 21, 2014
    Posts:
    8
    It would be really nice to see the DebuggerHidden attribute supported! Especially for generated code I don't want to step through all that generated code when debugging. This could also hide stuff in the stacktrace of the console view in Unity. So we don't always see UnityEngine.Debug:Log(Object) in the stacktrace. There are already options to show different detail of stacktraces for the console view. So add another one to hide/unhide DebuggerHidden methods.

    Something like this:

    None
    ScriptOnly
    ScriptOnlyWithHiddenMethods
    Full
     
  8. Deni35

    Deni35

    Joined:
    Jul 10, 2012
    Posts:
    43
    I downloaded the beta and checked DebuggerHidden. Unfortunately it still does not work.
     
  9. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,936
    Yes, sorry, we've not made any progress on supporting this attribute yet. It it still something I would like to support, but I'm not sure when we will get it.
     
  10. fwalkerCirca

    fwalkerCirca

    Joined:
    Apr 10, 2017
    Posts:
    57
    Any progress on this ?
     
    SugoiDev likes this.
  11. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,936
    Unfortunately we've not picked this up yet.
     
  12. fwalkerCirca

    fwalkerCirca

    Joined:
    Apr 10, 2017
    Posts:
    57
    Ahhhh,, You are killing me !
    How about the possibility of intercepting the console's double click? I am looking and looking an can't find anything.
    Is the only solution to write a console from scratch?
    All I want if for my logs to go to the right place WITH OUT using a .dll . I did get the working.
    I also would no mind adding the ability to click anywhere in the stack ! :)
     
  13. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,936
    I don't think we can intercept the double click. That will need to happen in the code editor or the debugger GUI, I think.
     
  14. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,123
    Any update on this? I have my own debugging class, as per Unity's optimisation guidelines:
    https://docs.unity3d.com/Manual/BestPracticeUnderstandingPerformanceInUnity7.html
    See Debug code & the [conditional] attribute.

    But this means every time I double click on an error, it takes me to my tiny script containing my static debugging utility class.

    I would like to just throw on a [DebuggerHiddenAttribute] on there and have the Unity console ignore that file, and take me to the actual problem.
     
    Xarbrough likes this.
  15. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,936
    We've not worked on supporting this yet.
     
  16. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    Please Unity, add DebuggerHidden to skip over wrapper methods when stepping through code and also in log stack traces.

    There’s really no replacement for the builtin console. I’ve tried the major store plugins but none is good enough for something so essential. Also, rerouting logs in Unity is too much overhead and causes performance issues when I implement my own console window. So, this attribute feature seems like a really good cost-benefit.
     
    pvloon and Prodigga like this.
  17. SugoiDev

    SugoiDev

    Joined:
    Mar 27, 2013
    Posts:
    395
    Even if you have a replacement console, the actual log file will still be polluted.
    I have a relatively simple logging framework and it bothers me deeply when I have to read polluted log files. I end having to cleanup the files with sed before I can read them easily.

    In editor I use EditorConsole Pro and ignore a bunch of stuff. Previously, I was hot-patching the ExtractFormattedStackTrace method, and I had full control over what to ignore. But it now has a hot path that is on the unmanaged side, so I can't readily patch it anymore.


    I don't have any solution currently, sadly. If any of you have any idea on how we could improve this, I'm interested!
     
    Prodigga likes this.
  18. Ruhan-_-

    Ruhan-_-

    Joined:
    Sep 14, 2016
    Posts:
    20
    upload_2021-9-21_17-58-42.png

    https://unity.com/roadmap/unity-platform/editor

    This issue to simply "remove the first log in a stack trace to ignore custom wrapper for Debug.Log" was brought up back in 2016.
    It is now 2021, Unity still isn't even close to implementing it. It's under consideration in their roadmap. We still have to constantly face this annoyance of double clicking a custom wrapped log only to navigate back to console and click second stack trace line. For my own custom solution a dll isn't an option because I do some stuff with custom enums that'll expand over time.

    :cool::cool::cool:
    @Everyone reading this, PLEASE DO THE FOLLOWING TO GET UNITY'S ATTENTION:
    1. Go to the link: https://unity.com/roadmap/unity-platform/editor
    2. Scroll down to "Under Consideration" section
    3. Find and Open "Console window improvements"
    4. Click "Critical" and state a reason why, provide email and hit Submit.
    upload_2021-9-21_18-1-33.png
     
    hugeandy likes this.