When you are in debugging mode and are single stepping through your code, the page that holds this memory address is made read-only and we will hit an exception once for every C# line of code. That is the "cmp dword ptr, 0" instructions we saw above. It works by sprinkling (actually, once for each C# line) the jit-code with reads from a specific memory address. The reason this works at all is that Mono has a built in system for debugging scripts. Locate the Unity process and attach to it. Go to Debug menu and select Attach to Process (NOTE: this is not the same option you usually choose for attaching to Unity). Let us start up a new instance of Visual Studio.įor this to work you probably (I didn't check to be honest) need to have selected C++ as one of the languages when you installed VS. So now your script is stuck and Unity seems to be hung. Observe Unity freeze up and experience the onsetting rush of panic until you remember that this is just a test. "Mind you, you'll keep sinking forever!!", - My mom The script should contain this code: using UnityEngine Fire up Unity and create an empty project, add a box to an empty scene and create a new C# script “Quicksand” attached to the box. What could possibly go wrong?Īs a trained professional you know the value of practice, so try this out on a toy project before you attempt a rescue operation at work. Or just hang on for the fun of a little tour into disassembled, jit'ed code. Until we get that feature properly done and release it, you can use the trick below. But it was not until my first Hack Week here, that I got to talk to the right people and realized why the trick works and how it may be used to create a proper way to break scripts in Unity ( sneak peek of my Hack Week project). Some years back, before joining Unity, I found a way to break a script that is stuck like this. But usually only if you can guess the right place in the code to set a breakpoint. If you were lucky enough to have the debugger attached before running your game, you may be able to break it. Unity becomes unresponsive and you may have to kill the Editor entirely to get out of the mess. If you have experienced an infinite loop in your script code in Unity, you know it is quite unpleasant. And then there was the broken data structure traversed by an algorithm that assumed current = current.next would surely lead to an end eventually. Another time a degenerate mesh sent a NaN right into an unsuspecting while(1) loop. Once it was the broken random function returning 1.000001 on impossibly rare cases. But from time to time, I’ve encountered them in sneaky variants. Infinite loops seems to be something that should be easily avoidable.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |