Last active
December 20, 2015 11:19
-
-
Save FredDeschenes/6121949 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace ObjectClonerCrashDemo | |
{ | |
class MainClass | |
{ | |
public static void Main (string[] args) | |
{ | |
//This runs fine inside MonoDevelop/VisualStudio 2012 | |
Lib.TestRunner.Run(); | |
Console.WriteLine("Done"); | |
Console.Read(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
As you can see, it crashes weirdly at line 24 in ObjectExtensions with a NullReferenceException, which is weird since there is a null check on this object on the previous line. | |
Doing anything to the object (ie: trying to log it) just moves the error inside String's constructor or String.Format. | |
Surrounding the line with a try/catch and adding a breakpoint in the catch crashes Unity as soon as the breakpoint is hit, but you can step-in up to this point. | |
You can download a ZIP file containing the VS2012 solution and Unity demo project here if you want to take a look : https://mega.co.nz/#!0AdlibqB!X5M6T07z58rqLHIEpi7JSk5nvAJICocV_DiEdcuhZy0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class TestScript : MonoBehaviour | |
{ | |
void Start () | |
{ | |
//Crash happens inside here in Unity | |
Lib.TestRunner.Run(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
namespace Lib | |
{ | |
public static class TestRunner | |
{ | |
public static void Run() | |
{ | |
ToClone temp = new ToClone(); | |
temp.shouldWork = 1234; | |
temp.willCrash = new List<object>() { new object(), new object() }; | |
var clone = ObjectExtensions.Copy(temp); | |
Debug.Assert(clone.shouldWork == temp.shouldWork); | |
Debug.Assert(clone.willCrash.Count == temp.willCrash.Count); | |
} | |
} | |
public class ToClone | |
{ | |
public int shouldWork; | |
public List<object> willCrash; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NullReferenceException: Object reference not set to an instance of an object | |
System.ObjectExtensions.InternalCopy (System.Object originalObject, IDictionary`2 visited) (at c:/Users/fDeschenes/Desktop/ObjectClonerCrashDemo/Lib/ObjectExtensions.cs:24) | |
System.ObjectExtensions+<>c__DisplayClass3.<InternalCopy>b__0 (System.Array array, System.Int32[] indices) (at c:/Users/fDeschenes/Desktop/ObjectClonerCrashDemo/Lib/ObjectExtensions.cs:34) | |
System.ArrayExtensions.ArrayExtensions.ForEach (System.Array array, System.Action`2 action) (at c:/Users/fDeschenes/Desktop/ObjectClonerCrashDemo/Lib/ObjectExtensions.cs:91) | |
System.ObjectExtensions.InternalCopy (System.Object originalObject, IDictionary`2 visited) (at c:/Users/fDeschenes/Desktop/ObjectClonerCrashDemo/Lib/ObjectExtensions.cs:34) | |
System.ObjectExtensions.CopyFields (System.Object originalObject, IDictionary`2 visited, System.Object cloneObject, System.Type typeToReflect, BindingFlags bindingFlags, System.Func`2 filter) (at c:/Users/fDeschenes/Desktop/ObjectClonerCrashDemo/Lib/ObjectExtensions.cs:60) | |
System.ObjectExtensions.InternalCopy (System.Object originalObject, IDictionary`2 visited) (at c:/Users/fDeschenes/Desktop/ObjectClonerCrashDemo/Lib/ObjectExtensions.cs:39) | |
System.ObjectExtensions.CopyFields (System.Object originalObject, IDictionary`2 visited, System.Object cloneObject, System.Type typeToReflect, BindingFlags bindingFlags, System.Func`2 filter) (at c:/Users/fDeschenes/Desktop/ObjectClonerCrashDemo/Lib/ObjectExtensions.cs:60) | |
System.ObjectExtensions.InternalCopy (System.Object originalObject, IDictionary`2 visited) (at c:/Users/fDeschenes/Desktop/ObjectClonerCrashDemo/Lib/ObjectExtensions.cs:39) | |
System.ObjectExtensions.Copy (System.Object originalObject) (at c:/Users/fDeschenes/Desktop/ObjectClonerCrashDemo/Lib/ObjectExtensions.cs:19) | |
System.ObjectExtensions.Copy[ToClone] (Lib.ToClone original) (at c:/Users/fDeschenes/Desktop/ObjectClonerCrashDemo/Lib/ObjectExtensions.cs:66) | |
Lib.TestRunner.Run () (at c:/Users/fDeschenes/Desktop/ObjectClonerCrashDemo/Lib/TestRunner.cs:14) | |
TestScript.Start () (at Assets/Scripts/TestScript.cs:9) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment