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. Dismiss Notice

Question StreamBinaryReader fails in build

Discussion in 'Entity Component System' started by vildauget, Apr 10, 2021.

  1. vildauget

    vildauget

    Joined:
    Mar 10, 2014
    Posts:
    120
    Entities Version 0.17.0-preview.41
    Build Windows Classic Build with IL2CPP

    Using StreamBinaryReader and StreamBinaryWriter works fine in editor. However, in build it fails to read, both if I try at start of game, or as a command when running.

    I've tested moving my save file between build and editor, and can confirm that StreamBinaryWriter works fine in build, and the saved file opens without problem in the editor.

    So is this a bug, or am I doing it wrong?

    The reading part of code:
    Code (CSharp):
    1. if (System.IO.File.Exists(file))
    2.                 using (var myReader = new StreamBinaryReader(file))
    3.                 {
    4.                     var nbOfRecords = myReader.ReadInt();

    From Player.Log:
    Code (CSharp):
    1. Could not open file Jallaballa0.sav for read
    2.  
    3. IOException: Failed to read from Jallaballa0.sav!
    4.   at Unity.Entities.Serialization.StreamBinaryReader.ReadBytes (System.Void* data, System.Int32 bytes) [0x00000] in <00000000000000000000000000000000>:0
    5.  
     
  2. vildauget

    vildauget

    Joined:
    Mar 10, 2014
    Posts:
    120
    when you google your problem, and find your own post...

    but then I noticed something strange - how's this supposed to work, haha?

    Unity.Entities.Serialization:


    public StreamBinaryReader(string filePath, long bufferSize = 65536)
    {
    if (string.IsNullOrEmpty(filePath))
    throw new ArgumentException("The filepath can neither be null nor empty", nameof(filePath));

    #if UNITY_EDITOR
    stream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
    buffer = new byte[bufferSize];
    #else
    bytesRead = 0;
    this.filePath = filePath;
    #endif
    }
     
    DevViktoria likes this.