Search Unity

Feedback Make DisposeSentinel.m_StackTrace public

Discussion in 'Entity Component System' started by friflo, Dec 22, 2020.

  1. friflo

    friflo

    Joined:
    Jan 16, 2016
    Posts:
    10
    Hi,
    doing this would give the possibility to check for leaks of NativeContainer's in Unit Test via assertions.
    I tried to access m_StackTrace via reflection, but it always returns null. So no chance to assert this.

    Code (CSharp):
    1.     // Log unit test leaks of native containers
    2.     public class ECSLeakTestsFixture : ECSTestsFixture
    3.     {
    4.         AtomicSafetyHandle m_Safety;
    5.         DisposeSentinel ds;
    6.            
    7.         [SetUp]
    8.         public override void Setup()
    9.         {
    10.             base.Setup();
    11.             DisposeSentinel.Create(out m_Safety, out ds, 0, Allocator.Invalid);
    12.         }
    13.  
    14.         [TearDown]
    15.         public override void TearDown() {
    16.             FieldInfo stackTraceField = ds.GetType().GetField("m_StackTrace", BindingFlags.Instance | BindingFlags.NonPublic);
    17.             object stackTrace = stackTraceField.GetValue(ds); // Always null. Even when DisposeSentinel.Dispose() log errors to the console
    18.  
    19.             DisposeSentinel.Dispose(ref m_Safety, ref ds);
    20.             base.TearDown();
    21.         }
    22.     }
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Have you enabled full stack trace on leak detection? Otherwise it'll always be null.
     
  3. friflo

    friflo

    Joined:
    Jan 16, 2016
    Posts:
    10
    Yes, I made the test with LeakDetection: On & Full Stack Trace. In both cases m_StackTrace is set and errors are written to the console. With the Debugger I can verify that in both cases m_StackTrace is set.