Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Hoeloe · Jan 18, 2015 at 12:02 PM · editorbuildcrashfreeze

Unity application randomly freezing on occasion

So, I've been making a Unity game, and there's been some weird behaviour that's been happening for a while.

My game runs fine. After loading, I get good performance, and can play the game no problem. It all works.

Except that very occasionally (about 1/5 times I run the game), at some point during execution (usually about 6 minutes in, but not exclusively), the game freezes. Everything on screen stops moving, and all audio sources continue to play a short section on loop (giving an effect like a stuck record). Sometimes this resolves itself after a few seconds, but most of the time it requires Unity to be shut down. This occurs in both the final build and the editor. If it occurs in the editor, no error messages appear, but the editor interface stops working, requiring the editor to be shut down manually.

I don't think there can be anything with my code that causes such an error, especially since it occurs at such radically different points during the game, but I was wondering if anyone else had experienced this, and if so, what they did about it. If no-one has experienced it, then it most likely is something wrong with my code, and I should have a look at it.

Comment
Add comment · Show 22
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 Unitraxx · Jan 18, 2015 at 02:49 PM 0
Share

2 things that I can think of are: You might enter an infinite loop; You entered a deadlock situation in a thread;

avatar image Hoeloe · Jan 18, 2015 at 02:52 PM 0
Share

It's not an infinite loop, or the sounds wouldn't continue playing (I don't think anyway). I'm also not using any threading thanks to only having Unity Indie.

I'll double check my code for infinite loops though.

avatar image Hoeloe · Jan 18, 2015 at 03:13 PM 0
Share

I've looked through all the for and while loops in my code. $$anonymous$$ost can never be put into a loop, and those which are more complicated are never in a system that will cause them to loop. I added some more checks anyway, but I doubt it will solve the issue.

avatar image Hoeloe · Jan 18, 2015 at 03:24 PM 0
Share

It's not that. It just happened again. It's definitely not an infinite loop, because the sounds start skipping a few seconds before the image freezes. These would happen simultaneously if it were because of an infinite loop.

avatar image tanoshimi · Jan 18, 2015 at 05:01 PM 0
Share

Have you checked the Log? (not the Console)

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Glurth · Jan 21, 2015 at 07:35 PM

Ok, I too had some trouble with pausing the debugger during some tests. Breakpoints worked fine, but are too cumbersome for a situation like yours. So I wrote this, maybe it will help you narrow stuff down:

 using System;
 using System.Threading;
 //Author: Glurth
 //Puropose:
 //  Sometimes using the Pause option on the debugger does not work.  Breakpoints however DO seem to work.
 //  This class can be used to detect infitine-loops or similar problems, and terminate the program.
 //Usage:
 //  At various places throughout your code call CrashDetector.SetExePoint(string), passing a unique string value each time.
 //    The first time you call SetExePoint, it will start monitoring
 //      You should call SetExePoint with a different value at least once in a while
 //    If it does NOT get a diferent value after a particular counter threshold is reached, It will terminate the main thread! (unity.exe)
 //
 //  If Using the debugger:  you can add a breakpoint to the /*put a breakpoint here*/ line, in the code below.
 //      Check the value of lastExecPoint in the debugger when it hits the breakpoint, to see where your last call to SetExePoint was.
 
 
 static class CrashDetector
 {
     static string execPoint;
     static string lastExecPoint;
     static long lastExecPointTime;
     static long crashTimeTreshold=100000;
     static Thread monitoringThread;
     static string dontCountPoint="No Exec points set yet. 10923$$#!!";
     
     static CrashDetector()
     {
         execPoint=dontCountPoint;
         lastExecPoint=dontCountPoint;
         monitoringThread= new Thread(CrashDetectorThread);
         monitoringThread.Start(Thread.CurrentThread);
     }
     
     public static void SetExePoint(string exe_point){execPoint=exe_point;}
     public static void SetCrashTimeTreshold(long newThreshold){crashTimeTreshold=newThreshold;}
     
     static void CrashDetectorThread(object calling_thread)  // use Thread.CurrentThread when calling function, to set this param
     {
         Thread mainthread=(Thread) calling_thread;
         long crash_counter=0;
         while(true)// infite-loop detector loop: I love ironic code
         {
             if(dontCountPoint!=lastExecPoint)// have ANY execution points been set yet?
                 crash_counter++;
             
             //WARNING:  this code does not yet include a threadsafe read of the execPoint or crashTimeTreshold variables used below
             if(execPoint!=lastExecPoint)// have we reached a new execution point- if so, reset count
             {
                 lastExecPoint=execPoint;
                 crash_counter=0;
             }
             if(crash_counter>crashTimeTreshold) //if too long has passed without change of execution point
             {
                 /*put a breakpoint here*/
                 //Debug.Log("aborting main thread:" + lastExecPoint);
                 mainthread.Abort();  // terminates main thread (e.g unity.exe: this will close unity)
                 mainthread.Join ();  // Waits untill that thread is closed
                 return; // closes this thread cleanly.
             }
             Thread.Sleep(0); // counter not execeeded: relinquish remainder of this thread's processing timeslice.
         }
     }
 }
 
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

29 People are following this question.

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

Related Questions

Crash in build when reloading level with a Sprite Renderer in the scene 0 Answers

Editor keeps freezing during build 0 Answers

Editor crashes on play 0 Answers

How can I find editor log file? 5 Answers

Unity crashes with Access Violation 2 Answers


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