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

Anonymous pipes, streamReader.ReadLine() crashes process

Discussion in 'Scripting' started by VinQbator, Dec 15, 2015.

  1. VinQbator

    VinQbator

    Joined:
    Aug 9, 2014
    Posts:
    12
    I'm trying to pass information between non-unity servermanager and unity server using anonymous pipes, which seems like an easy solution at the first place, but im getting a crash when testing it. I'm passing in handle as commandline argument from a parent process(servermanager) and it gets the sync message correctly, but when trying to read additional lines after that the process just freezes with a white screen nothing appearing at all. Since it is a standalone process, i have no idea how to debug it. output_log.txt only shows information about the build.

    Part of the code that crashes is here
    Code (CSharp):
    1. void Start ()
    2.     {
    3.         GetHandles();
    4.         StartCoroutine(IncomingStream());
    5.     }
    6.  
    7. IEnumerator IncomingStream()
    8.     {
    9.         string temp;
    10.         if (!synced)
    11.         {
    12.             pipeInStream = new AnonymousPipeClientStream(PipeDirection.In, inHandle);
    13.             streamReader = new StreamReader(pipeInStream);
    14.             do
    15.             {
    16.                 temp = streamReader.ReadLine();
    17.             }
    18.             while (!temp.StartsWith("SYNC"));
    19.             Debug.Log("Synced in stream");
    20.             synced = true;
    21.         }
    22.         while (true)
    23.         {
    24.             temp = streamReader.ReadLine(); //if commented out, everything works fine
    25.             Debug.Log(temp);
    26.             yield return new WaitForSeconds(1f);
    27.         }
    28.     }
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,201
    StreamReader.ReadLine blocks until it reads a newLine (according to here), so you'll have to check if there's actually data there. The example on MSDN uses StreamReader.Peek() >= 0 to check for that.
     
  3. VinQbator

    VinQbator

    Joined:
    Aug 9, 2014
    Posts:
    12
    I have already tried that before and just to be sure tried again, still doesn't work. Freezes exactly the same. Besides i cant find any reference to blocking until new line comes, i can just see that it returns null if there is no new line to read, which was what i was hoping to see in debug.log.

    EDIT: Just doing a Peek() without ReadLine() after syncing is enough to freeze the process.
     
    Last edited: Dec 15, 2015