In Unity, the editor hangs up. If you knock the program (for wines), it also hangs (no responding). I can not find the reason: I perform the same action an indefinite number of times and then hang. I cannot put breakpoint because it is not clear where to put them. It seems to me that it hangs somewhere in unit scripts.

How can I get a place in which the program hangs? Is it possible to see some kind of journal where all actions of the program are written out? I think that somewhere an infinite loop turns out, although I checked all the cycles ...

Thank!

  • one
    And MonoDevelop is? Theoretically, the forced break should work .... a la youtu.be/X8aw1n1ZJQo - Alexey Shimansky
  • @ Alexey Shimansky, Yes, MonoDevelop is really convenient to view the call stack. In the studio for some reason this does not work. I solved the problem, thanks! - Valera Kvip
  • in theory, the studio also has a break all , which also has to stop at the point of hangup .... but even that is not so simple, it seems there ......... in the end, through the mono it grabbed? and the fact that the blog is written in the first link did not try? - Alexey Shimansky
  • @ Alexey Shimansky, I tried, but there is not readable. - Valera Kvip
  • one
    Everything. Now it will be readable (I think). Specially moved everything in response. I think it will be a necessary and important thing here - Alexey Shimansky

1 answer 1

There are at least three solutions (if there are others - let me know): two quick and one long. And what is long connected with Visual Studio (why can't Microsoft have it all simple?)


The fastest (but financially expensive)

You need to go to the UnityAssetStore and find an asset called Panic Button . It is located in the Editor Extensions / System section. At the moment, this asset is right here .

What is he doing? When the application is spinning in an infinite loop and the Unity interface is hanging, just press the Shift + Esc keys and the main thread "breaks", the interface hangs. At the same time, the playback is paused, and the problem location is displayed on the console:

enter image description here

How exactly does it work? What happens inside? Most likely, what will be described in paragraph 3, only made in the form of a script, packaged in a dll (so that no one can see the code), connected to the project.


Use MonoDevelop

The steps are as follows:

  • We write a script with an infinite loop, hang it on the object and click Play :-)
  • Go to MonoDevelop and click RunAttach To Process

    enter image description here

  • In the window that appears, select Unity and click Attach

    enter image description here

  • Push the Pause button in MonoDevelop

    enter image description here

  • Mono will already stop in the problem area and StackTrace will be StackTrace

    enter image description here

  • It now remains to put Breakpoint on the line, change the value that enters into an infinite loop (in this case, assign i a value of 20, for example) and click Continue Execution

    enter image description here

  • To sigh with a relief.


Use Visual Studio

Steps:

  • We write a script with an infinite loop, hang it on the object and click Play :-)

    For example, the script is:

     using UnityEngine; public class Quicksand : MonoBehaviour { void OnMouseDown() { while(true) { // "Mind you, you'll keep sinking forever!!", -- My mom } } } 
  • Go to Visual Studio , click on the menu DebugAttach to Process and select Unity in the process list.

    Note (!) : It Attach to Process , NOT Attach To Unity

    enter image description here

  • Next, click DebugBreak all to stop the process.

  • It is necessary to find the disassembled view (if it does not automatically appear). In theory, on the StackTrace tab, if you double-click the LMB , a window will appear in which you can click the view disassembly link

    enter image description here

    And through the stack to get to the hang. The animation below should fully show how to get there:

    enter image description here

  • As a result, we get about the following picture:

    enter image description here

    It almost shows an endless loop.

    In reality, the code can be more difficult and it will be difficult to quickly figure out what is happening there, but you can not go into much, because there is a small trick (see the next step):

  • F10 - take a step in debugging without going into a function / method. Accordingly, now step by step we press F10 until we fly from line 000000001015A758 jmp 000000001015A743 to the line with the instruction cmp dword ptr [r11], 0 .

    enter image description here

    As a result, these values ​​should appear in the Autos tab in Visual Studio :

    enter image description here

  • Now just change the value of the "variable" R11 to zero (0)

    enter image description here

  • Since we are standing at the cmp address, when attempting to execute the instruction, it will try to read address 0, which, in turn, will generate an error. What we do: Press F5 (continue program execution), and then select Continue in the pop-up window.

    enter image description here

  • In theory, Unity should come to life and spit a mistake into the console, indicating where the catch was:

    enter image description here

  • To sigh with a relief.


PS The way with Visual Studio was borrowed in the Unity blog . There you can read why the method works enter image description here

  • 2
    how many bukaff - Bald
  • one
    Thank you, I tried%) - Alexey Shimansky
  • An excellent answer, but could you explain why it is Attach to Process , and NOT Attach To Unity ? :) - Denis Bubnov
  • one
    @DenisBubnov This is apparently due to the mechanics of the VS itself. Because through Attach to Process we can attach to any active process in Windows at all and work it off. For example, when a program crashes and a debugging window appears - you can work with it in VS ... That is, some kind of fine debugging and, just the same, work with disassembled code. In Attach To Unity there is no such thing. - Alexey Shimansky
  • one
    @DenisBubnov and he never really worked for me. Therefore, earlier yuzal VS Tools for unity from syntaxTree , which made a plugin especially for debugging under a unit, until Microsfoft bought them and now it cuts itself and already in new VS (at least in 2015 for sure) there is such a point in the IDE ( open unity solution) - Alexey Shimansky