From 730bc664ac91499e501269d2d1d60c286a0a4f45 Mon Sep 17 00:00:00 2001 From: Misaki Date: Thu, 2 Apr 2026 19:34:36 +0900 Subject: [PATCH] feat(dispose): add detailed debug output with stack trace Enhanced Dispose() in HashMapHelper, UnTypedArray, and UnsafeArray to provide more informative debug messages when called on uninitialized or already disposed objects. When MHP_ENABLE_STACKTRACE is defined, the debug output now includes a stack trace with file, type, method, and line number details. Also incremented project version to 1.6.5. --- .../Collections/HashMapHelper.cs | 18 +++++++++++++++++- .../Collections/UnTypedArray.cs | 18 +++++++++++++++++- .../Collections/UnsafeArray.cs | 18 +++++++++++++++++- .../Misaki.HighPerformance.LowLevel.csproj | 2 +- 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/Misaki.HighPerformance.LowLevel/Collections/HashMapHelper.cs b/Misaki.HighPerformance.LowLevel/Collections/HashMapHelper.cs index 9741167..658f6e0 100644 --- a/Misaki.HighPerformance.LowLevel/Collections/HashMapHelper.cs +++ b/Misaki.HighPerformance.LowLevel/Collections/HashMapHelper.cs @@ -719,7 +719,23 @@ public unsafe struct HashMapHelper : IDisposable { if (!IsCreated) { - Debug.Fail("The UnsafeArray is not created or already disposed."); + var message = "The HashMapHelper is not created or already disposed."; +#if MHP_ENABLE_STACKTRACE + var stackTrace = new StackTrace(1, true); + var sb = new System.Text.StringBuilder(); + foreach (var frame in stackTrace.GetFrames()) + { + var fileName = frame?.GetFileName(); + if (frame != null) + { + var methodInfo = DiagnosticMethodInfo.Create(frame); + sb.AppendLine($"File: {fileName}, Type: {methodInfo?.DeclaringTypeName}, Method: {methodInfo?.Name}, Line: {frame.GetFileLineNumber()}"); + } + } + + message += Environment.NewLine + sb.ToString(); +#endif + Debug.WriteLine(message); return; } diff --git a/Misaki.HighPerformance.LowLevel/Collections/UnTypedArray.cs b/Misaki.HighPerformance.LowLevel/Collections/UnTypedArray.cs index 136e084..2647437 100644 --- a/Misaki.HighPerformance.LowLevel/Collections/UnTypedArray.cs +++ b/Misaki.HighPerformance.LowLevel/Collections/UnTypedArray.cs @@ -273,7 +273,23 @@ public unsafe struct UnTypedArray : IUnTypedCollection { if (!IsCreated) { - Debug.Fail("The UnsafeArray is not created or already disposed."); + var message = "The UnTypedArray is not created or already disposed."; +#if MHP_ENABLE_STACKTRACE + var stackTrace = new StackTrace(1, true); + var sb = new System.Text.StringBuilder(); + foreach (var frame in stackTrace.GetFrames()) + { + var fileName = frame?.GetFileName(); + if (frame != null) + { + var methodInfo = DiagnosticMethodInfo.Create(frame); + sb.AppendLine($"File: {fileName}, Type: {methodInfo?.DeclaringTypeName}, Method: {methodInfo?.Name}, Line: {frame.GetFileLineNumber()}"); + } + } + + message += Environment.NewLine + sb.ToString(); +#endif + Debug.WriteLine(message); return; } diff --git a/Misaki.HighPerformance.LowLevel/Collections/UnsafeArray.cs b/Misaki.HighPerformance.LowLevel/Collections/UnsafeArray.cs index 4143ec0..fa40bc3 100644 --- a/Misaki.HighPerformance.LowLevel/Collections/UnsafeArray.cs +++ b/Misaki.HighPerformance.LowLevel/Collections/UnsafeArray.cs @@ -418,7 +418,23 @@ public unsafe struct UnsafeArray : IUnsafeCollection { if (!IsCreated) { - Debug.Fail("The UnsafeArray is not created or already disposed."); + var message = "The UnsafeArray is not created or already disposed."; +#if MHP_ENABLE_STACKTRACE + var stackTrace = new StackTrace(1, true); + var sb = new System.Text.StringBuilder(); + foreach (var frame in stackTrace.GetFrames()) + { + var fileName = frame?.GetFileName(); + if (frame != null) + { + var methodInfo = DiagnosticMethodInfo.Create(frame); + sb.AppendLine($"File: {fileName}, Type: {methodInfo?.DeclaringTypeName}, Method: {methodInfo?.Name}, Line: {frame.GetFileLineNumber()}"); + } + } + + message += Environment.NewLine + sb.ToString(); +#endif + Debug.WriteLine(message); return; } diff --git a/Misaki.HighPerformance.LowLevel/Misaki.HighPerformance.LowLevel.csproj b/Misaki.HighPerformance.LowLevel/Misaki.HighPerformance.LowLevel.csproj index 51f5c07..6c6e82a 100644 --- a/Misaki.HighPerformance.LowLevel/Misaki.HighPerformance.LowLevel.csproj +++ b/Misaki.HighPerformance.LowLevel/Misaki.HighPerformance.LowLevel.csproj @@ -7,7 +7,7 @@ true true Misaki - 1.6.4 + 1.6.5 $(AssemblyVersion) https://git.personalnas.com/Misaki/Misaki.HighPerformance.git https://git.personalnas.com/Misaki/Misaki.HighPerformance.git