[HeterochromiaFix] Fixed null reference exception #61

Merged
takahiro0327 merged 2 commits from fix-null-reference into master 2024-03-18 17:18:53 +00:00
takahiro0327 commented 2024-03-18 13:07:41 +00:00 (Migrated from github.com)

Fixed an exception when calling LoadFile in FreeH.

It will not reproduce if I do not have the plugin in my local environment. However, the fix itself is not a major disadvantage, and it is a good preparation for future changes.

NullReferenceException: Object reference not set to an instance of an object
  at IllusionFixes.HeterochromiaFix+Hooks.LoadFileLimitedPostfix (ChaFileControl __instance) [0x00005] in <287529fa9f6743858ecfbc9651184bcf>:0 
  at (wrapper dynamic-method) ChaFileControl.DMD<ChaFileControl::LoadFileLimited>(ChaFileControl,string,byte,bool,bool,bool,bool,bool,bool)
  at MyPlugin.GUIWindow (System.Int32 id) [0x00075] in <71b9c1e39de54c5eb4bcd67924955bfc>:0 
  at UnityEngine.GUILayout+LayoutedWindow.DoWindow (System.Int32 windowID) [0x00070] in <a0bccd5fb00b424ba4b8f758e660f824>:0 
  at UnityEngine.GUI.CallWindowDelegate (UnityEngine.GUI+WindowFunction func, System.Int32 id, System.Int32 instanceID, UnityEngine.GUISkin _skin, System.Int32 forceRect, System.Single width, System.Single height, UnityEngine.GUIStyle style) [0x00078] in <a0bccd5fb00b424ba4b8f758e660f824>:0 
Fixed an exception when calling LoadFile in FreeH. It will not reproduce if I do not have the plugin in my local environment. However, the fix itself is not a major disadvantage, and it is a good preparation for future changes. ``` NullReferenceException: Object reference not set to an instance of an object at IllusionFixes.HeterochromiaFix+Hooks.LoadFileLimitedPostfix (ChaFileControl __instance) [0x00005] in <287529fa9f6743858ecfbc9651184bcf>:0 at (wrapper dynamic-method) ChaFileControl.DMD<ChaFileControl::LoadFileLimited>(ChaFileControl,string,byte,bool,bool,bool,bool,bool,bool) at MyPlugin.GUIWindow (System.Int32 id) [0x00075] in <71b9c1e39de54c5eb4bcd67924955bfc>:0 at UnityEngine.GUILayout+LayoutedWindow.DoWindow (System.Int32 windowID) [0x00070] in <a0bccd5fb00b424ba4b8f758e660f824>:0 at UnityEngine.GUI.CallWindowDelegate (UnityEngine.GUI+WindowFunction func, System.Int32 id, System.Int32 instanceID, UnityEngine.GUISkin _skin, System.Int32 forceRect, System.Single width, System.Single height, UnityEngine.GUIStyle style) [0x00078] in <a0bccd5fb00b424ba4b8f758e660f824>:0 ```
ManlyMarco (Migrated from github.com) reviewed 2024-03-18 16:18:40 +00:00
@ -16,8 +16,12 @@ namespace IllusionFixes
#endif
internal static void LoadFileLimitedPostfix(ChaFileControl __instance)
ManlyMarco (Migrated from github.com) commented 2024-03-18 16:18:40 +00:00

This might still throw a nullref after exiting maker twice, since the Instrance can be a destroyed Unity Object that is not detected as null by the ? operator. Using a != null avoids the issue.

                var cvsEye02 = CustomBase.Instance != null ? CustomBase.Instance.gameObject.GetComponentInChildren<CvsEye02>(true) : null;

alternatively

                var cvsEye02 = CustomBase.Instance ? CustomBase.Instance.gameObject.GetComponentInChildren<CvsEye02>(true) : null;
This might still throw a nullref after exiting maker twice, since the Instrance can be a destroyed Unity Object that is not detected as null by the ? operator. Using a `!= null` avoids the issue. ```suggestion var cvsEye02 = CustomBase.Instance != null ? CustomBase.Instance.gameObject.GetComponentInChildren<CvsEye02>(true) : null; ``` alternatively ```suggestion var cvsEye02 = CustomBase.Instance ? CustomBase.Instance.gameObject.GetComponentInChildren<CvsEye02>(true) : null; ```
takahiro0327 (Migrated from github.com) reviewed 2024-03-18 17:06:01 +00:00
@ -16,8 +16,12 @@ namespace IllusionFixes
#endif
internal static void LoadFileLimitedPostfix(ChaFileControl __instance)
takahiro0327 (Migrated from github.com) commented 2024-03-18 17:06:00 +00:00

Thanks for the review. Fixed.
This spec is a Unity trap.

Thanks for the review. Fixed. This spec is a Unity trap.
ManlyMarco (Migrated from github.com) approved these changes 2024-03-18 17:17:47 +00:00
Sign in to join this conversation.
No description provided.