From 2b438660a18ee3083254c1c51a7884185dc9a731 Mon Sep 17 00:00:00 2001 From: Misaki Date: Thu, 2 Apr 2026 20:01:09 +0900 Subject: [PATCH] feat(dispose): add debug checks for double disposal Added debug-only checks in Dispose methods of HashMapHelper, UnTypedArray, and UnsafeArray to log a message (with optional stack trace) if Dispose is called on an uninitialized or already disposed instance, unless the buffer is null. Incremented assembly version to 1.6.6. --- .../Collections/HashMapHelper.cs | 7 +++++++ .../Collections/UnTypedArray.cs | 6 ++++++ Misaki.HighPerformance.LowLevel/Collections/UnsafeArray.cs | 7 +++++++ .../Misaki.HighPerformance.LowLevel.csproj | 2 +- 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Misaki.HighPerformance.LowLevel/Collections/HashMapHelper.cs b/Misaki.HighPerformance.LowLevel/Collections/HashMapHelper.cs index 658f6e0..25ef590 100644 --- a/Misaki.HighPerformance.LowLevel/Collections/HashMapHelper.cs +++ b/Misaki.HighPerformance.LowLevel/Collections/HashMapHelper.cs @@ -719,6 +719,12 @@ public unsafe struct HashMapHelper : IDisposable { if (!IsCreated) { +#if DEBUG + if (_buffer == null) + { + return; + } + var message = "The HashMapHelper is not created or already disposed."; #if MHP_ENABLE_STACKTRACE var stackTrace = new StackTrace(1, true); @@ -736,6 +742,7 @@ public unsafe struct HashMapHelper : IDisposable message += Environment.NewLine + sb.ToString(); #endif Debug.WriteLine(message); +#endif return; } diff --git a/Misaki.HighPerformance.LowLevel/Collections/UnTypedArray.cs b/Misaki.HighPerformance.LowLevel/Collections/UnTypedArray.cs index 2647437..6c37a97 100644 --- a/Misaki.HighPerformance.LowLevel/Collections/UnTypedArray.cs +++ b/Misaki.HighPerformance.LowLevel/Collections/UnTypedArray.cs @@ -273,6 +273,11 @@ public unsafe struct UnTypedArray : IUnTypedCollection { if (!IsCreated) { +#if DEBUG + if (_buffer == null) + { + return; + } var message = "The UnTypedArray is not created or already disposed."; #if MHP_ENABLE_STACKTRACE var stackTrace = new StackTrace(1, true); @@ -290,6 +295,7 @@ public unsafe struct UnTypedArray : IUnTypedCollection message += Environment.NewLine + sb.ToString(); #endif Debug.WriteLine(message); +#endif return; } diff --git a/Misaki.HighPerformance.LowLevel/Collections/UnsafeArray.cs b/Misaki.HighPerformance.LowLevel/Collections/UnsafeArray.cs index fa40bc3..861c0cc 100644 --- a/Misaki.HighPerformance.LowLevel/Collections/UnsafeArray.cs +++ b/Misaki.HighPerformance.LowLevel/Collections/UnsafeArray.cs @@ -418,6 +418,12 @@ public unsafe struct UnsafeArray : IUnsafeCollection { if (!IsCreated) { +#if DEBUG + if (_buffer == null) + { + return; + } + var message = "The UnsafeArray is not created or already disposed."; #if MHP_ENABLE_STACKTRACE var stackTrace = new StackTrace(1, true); @@ -435,6 +441,7 @@ public unsafe struct UnsafeArray : IUnsafeCollection message += Environment.NewLine + sb.ToString(); #endif Debug.WriteLine(message); +#endif return; } diff --git a/Misaki.HighPerformance.LowLevel/Misaki.HighPerformance.LowLevel.csproj b/Misaki.HighPerformance.LowLevel/Misaki.HighPerformance.LowLevel.csproj index 6c6e82a..f4c8ad0 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.5 + 1.6.6 $(AssemblyVersion) https://git.personalnas.com/Misaki/Misaki.HighPerformance.git https://git.personalnas.com/Misaki/Misaki.HighPerformance.git