Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Windows 10, Unity 5 and constant crashing

Discussion in 'Editor & General Support' started by ATLAS-INTERACTIVE, Aug 8, 2015.

  1. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    Since my upgrade to Windows 10, I have had nothing but crashes when running Unity, everything runs fine until I press play, sometimes (VERY occasionally) it manages to play without crashing but 9 times out of 10, it stops responding.

    I am in a new project started today with just 1 script in (posted below), so my immediate expectation was a severe incompatibility or missed step in compatibility with Windows 10 itself, but Unity 'seems' to run fine (sometimes) with an empty scene, so this may be a coding issue, or may be a much bigger issue with Windows 10.

    I should mention that I am on a high spec machine that used to have Unity crash maybe once every few months, so it's very unlikely to be a hardware issue.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.IO.Ports;
    3.  
    4. public class ArduinoInput : MonoBehaviour {
    5.  
    6.     public float speed;
    7.     private float amountToMove;
    8.  
    9.     SerialPort sp = new SerialPort("COM4", 9600);
    10.  
    11.     void Start ()
    12.     {
    13.         sp.Open();
    14.         //sp.ReadTimeout = 1;
    15.     }
    16.    
    17.     void Update ()
    18.     {
    19.         amountToMove = speed * Time.deltaTime;
    20.  
    21.         if (sp.IsOpen)
    22.         {
    23.             try
    24.             {
    25.                 MoveObject(sp.ReadByte());
    26.                 if (sp.ReadByte() != 0)
    27.                 {
    28.                     print(sp.ReadByte());
    29.                 }
    30.             }
    31.  
    32.             catch (System.Exception e)
    33.             {
    34.                 print(e);
    35.                 throw;
    36.             }
    37.         }
    38.     }
    39.  
    40.     void MoveObject(int direction)
    41.     {
    42.         if (direction == 1)
    43.         {
    44.             transform.Translate(Vector3.left * amountToMove, Space.World);
    45.         }
    46.  
    47.         if (direction == 2)
    48.         {
    49.             transform.Translate(Vector3.right * amountToMove, Space.World);
    50.         }
    51.     }
    52. }
     
  2. Sickwitit

    Sickwitit

    Joined:
    Dec 22, 2014
    Posts:
    123
    I would submit a bug report. I highly doubt it is your script. Just by looking at your case, the obvious cause is from upgrading to Windows 10. Not many people have ran through the tests with Windows 10 along with Unity 5 and some people are still running into bugs on Windows 8

    1. Is this the same project you ran prior to upgrading to Windows 10?
    2. What exact version of Unity are you using?
    3. Did you modify any of the Unity files, while outside Unity?

    If it's not windows 10, it could be an antivirus program. There has been tons of issues regarding antivirus software running with Unity 5. To be safe and to speed up your development time, I personally would go back to the previous working version of windows you were using. Sometimes the working version is the best version. I would also love to upgrade to Windows 8 or 10, but haven't because I have a stable version of my project on Windows 7.

    On the next project, I'll upgrade to Windows 8 or 10 depending on how stable it is.

    That's just my 2 cents
     
  3. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    1. This is a new project, started after my upgrade I'm afraid, but I have tested it on a Windows 7 machine and it does stop responding sometimes, but it is a lot more frequent with 10.

    2. I am running Unity 5.1.2f1

    3. I have not modified any of the Unity files or project files outside of Unity, although have added things like images, but they are not even used in the scene.
     
  4. Sickwitit

    Sickwitit

    Joined:
    Dec 22, 2014
    Posts:
    123
    I use the same patch 5.1.2f1 on my Windows 7 machine. I've actually ran into crashes because of dragging and dropping un-used images in the Unity asset file structures, outside of Unity. I then have to delete them out of Unity's file structure outside unity in order to run a successful project again. Maybe try starting a brand new project, without dropping any images in the file structure. Completely clean

    Also, how does your log file look?
     
  5. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    I have now started a new, clean project and rewritten the script and still getting the crashing.
    Is it possible that my issue is not just the version or OS, but an intolerance in Unity for serial port data?

    I have seen many other people use serial port data from an Arduino before, in fact my code is very largely based off of a tutorial for exactly that but everything I do seems to make Unity crash.
     
  6. Sickwitit

    Sickwitit

    Joined:
    Dec 22, 2014
    Posts:
    123
    Is your script causing the crashes? Disable it or get rid of it to check. It may narrow down your search. Your log file will help you file issues too.

    http://docs.unity3d.com/Manual/LogFiles.html
     
  7. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    It appears Unity is freezing and/or crashing due to the script, Unity will freeze until input from the serial port is given, then it works.

    If I stop sending the serial information (let go of the button) Unity freezes again and will accept no input, not even pressing stop or pause.

    Is there anything I can do to prevent Unity's apparent dependency on the serial data, or at least make it run without having to hold down a button?
     
  8. Alex-Lian

    Alex-Lian

    Guest

    It's not Unity's dependency so much as your code being called in the main loop with a call to ReadByte that the documents from Microsoft (and thus I assume mono) is a synchronous (i.e. blocking) call that's waiting for data before it lets any code (and thus the whole main loop since it's in update).

    You'll need to restructure your code to:
    - Either check that there's data read before reading
    or
    - Restructure to use a 2nd thread to be ok with blocking, but then have to shuffle data back to the main thread as needed.

    I'm sure there may be alternate solutions past that, but those are things that come to mind.
     
    Sickwitit likes this.
  9. rafabosse

    rafabosse

    Joined:
    Jul 8, 2015
    Posts:
    1
    Hi, today I report the same problemn with my project.
    Curious, three days ago, my project was working correctly.
    If you solve your problemn, please share!