Search Unity

Bug Double-clicking an error sometimes takes you to the wrong place.

Discussion in 'Editor & General Support' started by chemicalcrux, Mar 8, 2023.

  1. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    721
    First, here's the stack trace I got:

    Code (csharp):
    1. ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    2. Parameter name: index
    3. System.Collections.Generic.List`1[T].get_Item (System.Int32 index) (at <434571214be741f48f7262e1e0f039a1>:0)
    4. GraveyardGenerator.Free (UnityEngine.Vector2Int pos, UnityEngine.Vector2Int size) (at Assets/GraveyardGenerator.cs:74)
    5. GraveyardGenerator.Start () (at Assets/GraveyardGenerator.cs:42)
    I have a little level generator that needs to check if a space is free. It does so by calling a method called "Free".

    Line 42 in Start() is a call to Free(). Line 74 in Free() indexes a list.

    Free() is incorrectly written, so it sometimes runs out of bounds when it tries to index the list.

    When I double-click on the exception, it takes me to line 42, rather than line 74.

    Is this expected behavior? I've noticed this a few times before (usually with NullReferenceException, but that might just be because that's the most common one...). It feels like Unity is incorrectly deciding that Free() isn't "my code", and so shows me the place I call Free() instead.
     
  2. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    721
    Bumping this because it's happening to me some more! I'm not sure if this is a problem with VSCode, with my configuration of VSCode, or something wrong on Unity's end.

    Has anyone else seen this? It's pretty common.

    upload_2023-3-19_10-47-28.png

    Double-clicking this takes me to...

    upload_2023-3-19_10-47-39.png

    ...the place that enabled was set to true, rather than the line that the error happened on!