Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by g__l · Oct 22, 2015 at 08:12 AM · monodeveloploopfreezevisualstudiolooping

Help! Unsaved work stuck in frozen unity, believed to be from infinite loop. What can i do?

I used this code as i wanted to only move one way at a time to stick strictly to two axis but i believe i created an infinite loop from looking at http://answers.unity3d.com/questions/32826/can-the-unity-editor-break-out-of-an-infinite-loop.html, the question seemed to solve my problem but as i have the latest version of unity i now use visual studio not mono-develop so i am quite stuck. I will display my code so that you can maybe spot how to avoid an infinite loop while keeping the desired functionality.

 using UnityEngine;
 using System.Collections;
 
 public class Swivel : MonoBehaviour {
     public int speed;
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         int blah = 1;
         while (blah == 1)
         {
             if (Input.GetKey(KeyCode.LeftArrow))
             {
                 transform.Rotate(Vector3.up * Time.deltaTime * speed);
                 break;
             }
 
             if (Input.GetKey(KeyCode.RightArrow))
             {
                 transform.Rotate(Vector3.down * Time.deltaTime * speed);
                 break;
             }
 
             if (Input.GetKey(KeyCode.UpArrow))
             {
                 transform.Rotate(Vector3.left * Time.deltaTime * speed);
                 break;
             }
 
             if (Input.GetKey(KeyCode.DownArrow))
             {
                 transform.Rotate(Vector3.right * Time.deltaTime * speed);
                 break;
             }
         }
     }
 }

Visual studio is still working but i just need help to protect my unsaved work through the same technique as

I know it's an old question but I do have a better solution. As others have said: don't use an infinite loop by design. However if you did it by mistake and don't want to loose a whole scene or other unsaved data here's what you can do:

1) Open mono develop and attach it to the editor if you haven't already.(Run

Attach To Process)

2) Pause execution from mono develop.(Run > Pause)

3) Go to your immediate window (View > Debug Windows, if you don't see it at the bottom).

4) Modify the value that's causing you to loop infinitely. The Immediate window lets you just type in some code that will execute in that scope.

For me, the problem was looping over a list and trying to find a specific value that matched an element. I didn't properly handle the value not existing so it looped infinitely. All I had to do was call listname.Clear(); in the immediate window and the loop broke out on the next iteration.

If you were doing something exceptionally silly like while(true){ / some silly code / } you might be able to break out by just calling return. If you were calling that function every frame you might have to be a bit more sneaky and call T.Destroy(gameObject.GetComponent()) or something to that effect to remove the script that's calling that silly function.

I hope this helps someone else who doesn't want to nuke their work in progress!

Cheers.

Thank you for reading this and if you can help please help sooner rather than later as I am eager to finish off my work. Thanks!

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image g__l · Oct 21, 2015 at 09:44 PM 0
Share

I am having to turn my computer off so it is gone i believe but still it would be useful to know what was wrong with my code and how to fix it. Thanks

avatar image Bonfire-Boy · Oct 22, 2015 at 10:34 AM 0
Share

Sorry I don't know about breaking out of such a loop.

But the way to avoid the loop while keeping the (apparently) desired functionality is simply to remove the loop, ie delete these 4 lines...

 int blah = 1;
 while (blah == 1)
 {
 }

As it says in your code, Update() is called once every frame. So those conditions are going to be being checked every frame without the loop. All your loop does is keep the flow in that Update function and prevent Unity from getting on with anything else.

I'm afraid you are actually doing what the quote (which is from where?) describes as "something exceptionally silly".

avatar image g__l · Oct 25, 2015 at 12:30 PM 0
Share

Yes, i guess i did do 'something exceptionally silly' @Bonfire Boy as described in a comment in the answer that i linked

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Owen-Reynolds · Oct 22, 2015 at 07:53 PM

The time-honored, mostly official answer is: Save your work. You have to lose unsaved work several times before you learn to Save, make backups ... and this is one of those times.

A real project involves redoing and rewriting the same code over and over and over as insane managers come and go, testers hate what you have now ... . Having to redo a few days of lost work (which won't take nearly as long the second time) is good practice for this.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image g__l · Oct 25, 2015 at 12:26 PM 0
Share

Yes, i agree with you, doing it again will not be too bad. I would hope that in the future unity do work out how to stop infinite loops freezing unity, surely there is a way they can be identified and an error message shown. Thanks

avatar image Owen-Reynolds g__l · Oct 25, 2015 at 03:47 PM 0
Share

Well, sure, freezing everything on an infinite loop isn't something that should happen. And in most editors, it won't happen -- you can press the Stop button, in those. But no one can detect "bad" infinite loops (there are good ones, like Update.)

But it's due the the way Unity is made: being able to pause the game, move things around, and play with the Inspector while it runs. I suspect that pulling the running game apart from the editor (to fix the infinite loop freeze) would be a huge, huge pain, and might cause some features to be cut.

Surprisingly, after the first few times $$anonymous$$e froze, I just got used to this. I'm happy if this is on the bottom of their to-do list.

avatar image Awesomeking570 · May 13, 2021 at 03:51 PM 1
Share

there is actually a way to unfreeze your code by editing it in debug mode on visual studio. i commented a video that shows it.

avatar image
1

Answer by Awesomeking570 · May 13, 2021 at 03:50 PM

https://youtu.be/mL0vyU0H0Jg this video explains in pretty good depth exactly what to do if your unity completely freezes from a loop and you use visual studio

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to handle long loops 3 Answers

Unity Freezing 1 Answer

Mecanim animation Looping problem (Unity 4.6) 0 Answers

How do i make it rain spheres continuously in a loop in Cardboard SDK? 0 Answers

monodevelop vs visual studio? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges