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

C# Compiler Hard crash when debugging and inspecting C# 7.2 ref readonly properties

Discussion in 'Experimental Scripting Previews' started by strich, Jul 31, 2018.

  1. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    374
    Runtime: .NET 4.x
    Backend: Mono
    API Compatibility Level: .NET 4.x
    Relevant Packages: Incremental Compiler

    We've been using the new C# 7.2 featureset alongside the Incremental Compiler package and it has been pretty flawless so far!

    However we have just discovered that when we inspect/watch
    ref readonly
    properties returned from an array when debugging we get a hard crash. This is a pretty critical issue for us right now, as most of our codebase uses
    ref readonly
    .

    The current work around we have is that we assign the
    ref readonly
    to a local variable and so force it to copy and deref and debug that, however it is barely more convenient than Debug.Log. ;)

    Crash log:
    Code (CSharp):
    1. * Assertion: should not be reached at ..\mono\metadata\marshal.c:4147
    2. (0,0): watchdog triggered an exit
    Example code:
    Code (CSharp):
    1. public struct MyStruct {
    2.     public Vector2 Position;
    3. }
    4.  
    5. public class ExampleClass<T> where T: struct {
    6.     T[] MyArray = new T[256];
    7.  
    8.     public ref readonly T this[int index] => ref MyArray[index];
    9. }
    10.  
    11. var example = new ExampleClass<MyStruct>();
    12. var newPos = example[123].Position * 3; // This crashes when inspecting Position
    13. var localPos = example[123].Position; // Inspecting localPos after executing this line won't crash
     
    Qbit86 likes this.
  2. joncham

    joncham

    Unity Technologies

    Joined:
    Dec 1, 2011
    Posts:
    276
    What version of VS and VSTU are you using? I cannot reproduce this issue currently.
     
  3. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    374
    Latest of both.
    VS: 15.7.5
    VSTU: 3.7.0.1
    Unity: 2018.2.1f1
     
    Last edited: Jul 31, 2018
  4. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    374
    Worth noting that it is Unity that crashes - VS does not crash.
     
  5. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    374
    @joncham did you ever repro this? We get it daily.
     
  6. Magicolo

    Magicolo

    Joined:
    May 8, 2014
    Posts:
    5
    Hi, we have exactly the same bug when inspecting a 'ref return' property.

    This code is in an external DLL.
    Code (CSharp):
    1.  
    2. public struct Write<T>
    3. {
    4.     public ref T Value => ref _array[_index];
    5.  
    6.     readonly T[] _array;
    7.     readonly int _index;
    8.  
    9.     public Write(T[] array, int index)
    10.     {
    11.         _array = array;
    12.         _index = index;
    13.     }
    14. }
    15.  
    This code is in a Unity script.
    Code (CSharp):
    1.  
    2. var array = new int[] { 1, 2, 3 };
    3. var write = new Write<int>(array, 0);
    4. // break here and inspect 'write.Value'
    5.  
    Tried with Unity 2018.2.2f1
    and Visual Studio 15.8.1

    This is critical bug for us as it prevents us from debugging properly.
     
  7. Magicolo

    Magicolo

    Joined:
    May 8, 2014
    Posts:
    5
    Tried with Unity 2018.2.6f1
    and Visual Studio 15.8.2

    and bug still occurs.
     
  8. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,936
    I don't know that we've had a bug report for this issue. Could someone on this thread submit one? It looks like it has not been corrected yet.
     
  9. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    374
    Case 1077782
     
    JoshPeterson likes this.
  10. joncham

    joncham

    Unity Technologies

    Joined:
    Dec 1, 2011
    Posts:
    276
    I have reproed this issue and am fixing.
     
    WiredTexan and strich like this.
  11. ManuelSegura

    ManuelSegura

    Joined:
    Dec 12, 2015
    Posts:
    19
    Hello, this bug is happening again it's apparently being ignored. Pleas read this thread.
     
  12. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,936
    I think the issue on that thread is a different one. The bug report discussed above occurred when the C# compiler crashed. It looks like the bug report in the thread you linked to is related to a debugger crash.