From 98bc0693dd49744b7896aeddfbd971e1062caf0f Mon Sep 17 00:00:00 2001 From: Syntriax Date: Mon, 27 Oct 2025 08:51:27 +0300 Subject: [PATCH] fix: possible hash code collisions on Matrix4x4 --- Engine.Core/Primitives/Matrix4x4.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Engine.Core/Primitives/Matrix4x4.cs b/Engine.Core/Primitives/Matrix4x4.cs index 9ff3501..0288b41 100644 --- a/Engine.Core/Primitives/Matrix4x4.cs +++ b/Engine.Core/Primitives/Matrix4x4.cs @@ -240,10 +240,15 @@ public readonly struct Matrix4x4( public override bool Equals(object? obj) => obj is Matrix4x4 matrix && this == matrix; public bool Equals(Matrix4x4 other) => this == other; - public override int GetHashCode() => HashCode.Combine( - HashCode.Combine(M11, M12, M13, M14, M21, M22, M23, M24), - HashCode.Combine(M31, M32, M33, M34, M41, M42, M43, M44) - ); + public override int GetHashCode() + { + HashCode hashCode = new(); + hashCode.Add(M11); hashCode.Add(M12); hashCode.Add(M13); hashCode.Add(M14); + hashCode.Add(M21); hashCode.Add(M22); hashCode.Add(M23); hashCode.Add(M24); + hashCode.Add(M31); hashCode.Add(M32); hashCode.Add(M33); hashCode.Add(M34); + hashCode.Add(M41); hashCode.Add(M42); hashCode.Add(M43); hashCode.Add(M44); + return hashCode.ToHashCode(); + } public override string ToString() => $"Matrix4x4({M11}, {M12}, {M13}, {M14},{M21}, {M22}, {M23}, {M24},{M31}, {M32}, {M33}, {M34},{M41}, {M42}, {M43}, {M44})"; }