From 730f5976e70eba5a608c72b42251c6fe3bf5c88b Mon Sep 17 00:00:00 2001 From: Lisias Date: Thu, 8 Oct 2020 10:30:52 -0300 Subject: [PATCH] (Terrible) work around for https://github.com/net-lisias-ksp/KSPAPIExtensions/issues/7 --- KNOWN_ISSUES.md | 9 ++++++--- Source/FMRS/FMRS_Util.cs | 22 ---------------------- Source/FMRS/Log.cs | 34 ++++++++++++++++++++++++++++++++-- 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/KNOWN_ISSUES.md b/KNOWN_ISSUES.md index c480e9c..1849f1d 100644 --- a/KNOWN_ISSUES.md +++ b/KNOWN_ISSUES.md @@ -1,5 +1,8 @@ # FMRS :: Known Issues -* I could not make the thing to work on Unity5, ruling out KSP \<= 1.3.1 - + See [this code](https://github.com/net-lisias-kspu/FMRS/blob/e6008f51fc60dc2608de78b11fb44cd2daa85aae/Source/FMRS/FMRS_Util.cs#L206) (link to github) for a full explanation for this problem. - - I'm bafled. =/ +* There's a nasty problem (probably a stack overflow on OnAwake) affecting Unity 5 and 2017 that played havoc with the KSPe logging. + + Heavy disk I/O may aggravate the problem. + + This was the real issue when I first realised the problem on [this code](https://github.com/net-lisias-kspu/FMRS/blob/e6008f51fc60dc2608de78b11fb44cd2daa85aae/Source/FMRS/FMRS_Util.cs#L206). + + This can affect also [1.4.0 \<= KSP \<= 1.7.3], so Unity 2017 also have the problem + + Unity 2019 (KSP \>= 1.8) **is not affected**. + + Complete history on [KSPe's Issue #7](https://github.com/net-lisias-ksp/KSPAPIExtensions/issues/7) diff --git a/Source/FMRS/FMRS_Util.cs b/Source/FMRS/FMRS_Util.cs index 839c1cd..3badee8 100644 --- a/Source/FMRS/FMRS_Util.cs +++ b/Source/FMRS/FMRS_Util.cs @@ -203,28 +203,6 @@ public void set_save_value(save_cat cat, string key, string value) { Log.dbg("!ContainsKey {0}, {1}, {2}", cat, key, value); Log.dbg("Save_File_Content[{0}] check = {1}", cat, Save_File_Content.ContainsKey(cat)); - - /* - * Believe it of not, the line ahead was crashing KSP **on the spot!** - * - * Behaviour detected on KSP 1.3.1 (Mono 3.5, Unity5). Same for KSP 1.2.2. - * - * On KSP 1.4 (Mono 3.5, Unity 2017) things work fine! - * - * I tried many different solutions, but all I managed to do is to delay the crash to the next occurence of - * the Dictionary access. It's not a concurrency problem, I refactored all the access to the Save_File_Content - * and protected them on a critical section, no dice. - * - * This code is here since commmit 826baad (2014-0812), we are talking KSP V0.90 or older here. This could not pass unoticed - * all these years, the damn thing is crashing my KSP on Awake (on Main Menu), God Damnit! - * - * I don't have the slightest idea about what's happening, but it appears to be Unity5 related and I'm guessing it's something - * related to me using a MacOS machine for development (could not think on any other reason, and on Unity2017 I can't compile - * against the KSP/MAC Managed DLLs or the thing will not work on Windows, while by compiling using the Windows DLLs the damned thing runs - * on everything, including Macs. - * - * In a way or another, I'm dropping KSP 1.3.1 for while. - */ Save_File_Content[cat].Add(key, value); } diff --git a/Source/FMRS/Log.cs b/Source/FMRS/Log.cs index 0eba63e..9152828 100644 --- a/Source/FMRS/Log.cs +++ b/Source/FMRS/Log.cs @@ -36,42 +36,70 @@ namespace FMRS { public static class Log { +#if UNITY2019 private static readonly Logger log = Logger.CreateForType(); - +#endif internal static void force(string msg, params object[] @params) { +#if UNITY2019 log.force(msg, @params); +#else + if (null != @params && @params.Length > 0) UnityEngine.Debug.LogFormat(msg, @params); + else UnityEngine.Debug.Log(msg); +#endif } + [ConditionalAttribute("DEBUG")] internal static void info(string msg, params object[] @params) { +#if UNITY2019 Log.info(msg, @params); +#endif } + [ConditionalAttribute("DEBUG")] internal static void warn(string msg, params object[] @params) { +#if UNITY2019 log.warn(msg, @params); +#endif } + [ConditionalAttribute("DEBUG")] internal static void detail(string msg, params object[] @params) { +#if UNITY2019 log.detail(msg, @params); +#endif } + [ConditionalAttribute("DEBUG")] internal static void error(Exception e, object offended) { +#if UNITY2019 log.error(offended, e); +#else + UnityEngine.Debug.LogException(e); +#endif } + [ConditionalAttribute("DEBUG")] internal static void error(string msg, params object[] @params) { +#if UNITY2019 log.error(msg, @params); +#else + if (null != @params && @params.Length > 0) UnityEngine.Debug.LogErrorFormat(msg, @params); + else UnityEngine.Debug.LogError(msg); +#endif } [ConditionalAttribute("DEBUG")] internal static void dbg(string msg, params object[] @params) { +#if UNITY2019 log.trace(msg, @params); +#endif } #if DEBUG @@ -87,7 +115,9 @@ internal static void dbgOnce(string msg, params object[] @params) if (DBG_SET.Contains(new_msg)) return; DBG_SET.Add(new_msg); #endif +#if UNITY2019 log.trace(new_msg); +#endif } [ConditionalAttribute("DEBUG")] @@ -122,8 +152,8 @@ public static void PopStackInfo(string msg) } else Log.warn("Pop failed, no values on stack"); -#endif Log.detail(msg); +#endif } } }