Search Unity

Problems with FileStream.ReadAsync on WebGL loading of idbfs files

Discussion in 'Web' started by Bersaelor, Feb 25, 2021.

  1. Bersaelor

    Bersaelor

    Joined:
    Oct 8, 2016
    Posts:
    111
    Hey there,

    so, when I try to load files in the browser from the `idbfs` storage using ReadAsync, the file after the `await` never executes. It also doesn't send an error, it just fails.

    Using synchronous `Read()` works, but that just feels so clunky to me.

    Code (CSharp):
    1.        
    2.         log.debug("[GLTFLoader]: Opening Filestream to " + filePath);
    3.         using (FileStream SourceStream = File.Open(filePath, FileMode.Open))
    4.         {
    5.             result = new byte[SourceStream.Length];
    6.             log.debug("[GLTFLoader]: SourceStream " + SourceStream);
    7.             SourceStream.Read(result, 0, (int)SourceStream.Length);
    8.             // await SourceStream.ReadAsync(result, 0, (int)SourceStream.Length);
    9.         }
    10.         log.debug("[GLTFLoader]: finished loading " + result.Length);
    11.         return result;
    12.  
    Has anyone tried this before and got it to work using async+await?

    (Both methods work great in the editor or on macOS or Android)
     
  2. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    This would be interesting for us to take a peek. not sure what the discrepancy between WebGL and other platforms would be here. Would you be able to report this as a bug?
     
  3. Carlotes247

    Carlotes247

    Joined:
    Jun 12, 2014
    Posts:
    9
    I experience the same behaviour on an Oculus Quest using Unity 2020.1.17f. The code below
    Code (CSharp):
    1. using (FileStream SourceStream = File.Open(filePath, FileMode.Open) )
    2. {
    3. ....
    never executes and leaves my task without doing anything :/
     
  4. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    It would be great if this can be reported as a bug along with a test case, that would get the QA team attention to investigate the issue!