From 8a58855c7e27e5c6862766e6bc98055b869ae497 Mon Sep 17 00:00:00 2001 From: hvacengi Date: Mon, 7 Mar 2016 14:26:10 -0500 Subject: [PATCH] Fix recursion CalculatorStructure.cs * Fixed the root of the recursion issue. Some types (specifically Vector) have implicit conversions that caused TryCoerceImplicit to continue to call over and over until running out of memory. --- src/kOS.Safe/Compilation/CalculatorStructure.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/kOS.Safe/Compilation/CalculatorStructure.cs b/src/kOS.Safe/Compilation/CalculatorStructure.cs index 8c9bca1a3..2c94b4b3f 100644 --- a/src/kOS.Safe/Compilation/CalculatorStructure.cs +++ b/src/kOS.Safe/Compilation/CalculatorStructure.cs @@ -280,6 +280,14 @@ private bool TryCoerceImplicit(OperandPair pair, out OperandPair resultPair) bool couldCoerce = false; object newLeft; object newRight; + if (pair.LeftType == pair.RightType) + { + resultPair = null; + // Since the types are already the same, we can't coerce them to be the same. + // Otherwise, some types will act as if they have been coerced because of + // other implict conversions. + return false; + } MethodInfo convert2 = pair.LeftType.GetMethod("op_Implicit", FLAGS | BindingFlags.ExactBinding, null, new[] { pair.RightType }, null); if (convert2 != null) {