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 UnityWebRequestTexture.GetTexture behaviour changed?

Discussion in 'Scripting' started by truegod1205, Feb 3, 2023.

  1. truegod1205

    truegod1205

    Joined:
    Aug 18, 2015
    Posts:
    4
    Hello, I have some problems about get images from web.
    Images might be JPG, PNG, or GIF.
    However, the file format can only be known if the raw data is analyzed after downloading the images from this site.

    Therefore, at beginning,
    Code (CSharp):
    1. UnityWebRequest request = UnityWebRequestTexture.GetTexture(url);
    2. yield return request.SendWebRequest();
    3.  
    4. Texture2D Tex = ((DownloadHandlerTexture)request.downloadHandler).texture;
    5.  
    6. byte[] rawData = request.downloadHandler.data;
    7.  
    8. if (IsGif(rawData)) {/*...*/}
    If IsGIF, I could use rawdata directly.
    If it's not GIF, I could use Tex directly,

    I could do these things in one UnityWebRequest.
    it worked fine before Unity 2021.3.16f1 (LTS).

    However, when I changed to Unity 2021.3.17f1 (LTS).and did same things.
    If the URL image format is GIF.
    it would crash at
    Code (CSharp):
    1. UnityWebRequest request = UnityWebRequestTexture.GetTexture(url);
    2. yield return request.SendWebRequest();
    I know the "UnityWebRequestTexture.GetTexture" document said that "Only JPG and PNG formats are supported."

    But I am curious these behavior will crash after Unity 2021.3.17f1 (LTS)

    Thanks.
     
  2. spajus

    spajus

    Joined:
    Jun 10, 2015
    Posts:
    43
    I can confirm it started crashing on gifs since this version. Bug report submitted: IN-34327
     
    Last edited: Mar 6, 2023
  3. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,638
    I believe the fix for this bug is already in the pipeline.
    However, if you know that it's a GIF file, don't use the texture downloading, use the regular one. It's a waste of resources to attempt to decode an image, that is known to be unsupported.
     
  4. spajus

    spajus

    Joined:
    Jun 10, 2015
    Posts:
    43
    Is it possible to load an image from an arbitrary location on the player's computer without using the web request? That would be great.

    Oh wait, I could probably do File.ReadAllBytes and new Texture2D from that.
     
    Last edited: Mar 8, 2023