【问题标题】:Error m_InstanceID != 0 when downloading texture from the server从服务器下载纹理时出现错误 m_InstanceID != 0
【发布时间】:2017-01-30 10:27:38
【问题描述】:

尝试从服务器下载纹理时,我在 Unity 5.4 中遇到此错误。

这是代码(链接应该有效):

     UnityWebRequest www = UnityWebRequest.GetTexture("https://0.gravatar.com/avatar/fc2beef90fad49f83d79650a10b5c030?s=256&d=identicon&r=G");
     www.SetRequestHeader("Accept", "image/*");
     async = www.Send();
     while (!async.isDone)
         yield return null;
     if (www.isError) {
         Debug.Log(www.error);
     } else {
         tex = DownloadHandlerTexture.GetContent(www);    // <-------------------
     }

错误如下所示:

m_InstanceID != 0
UnityEngine.Networking.DownloadHandlerTexture:GetContent(UnityWebRequest)

【问题讨论】:

    标签: c# unity3d server textures webrequest


    【解决方案1】:

    这是一个错误。当www.isDoneasync.isDoneDownloadHandlerTexture 一起使用时会发生这种情况。

    解决方法是在调用DownloadHandlerTexture.GetContent(www); 之前等待另一个带有yield return null;yield return new WaitForEndOfFrame() 的帧。

    UnityWebRequest www = UnityWebRequest.GetTexture("https://0.gravatar.com/avatar/fc2beef90fad49f83d79650a10b5c030?s=256&d=identicon&r=G");
    www.SetRequestHeader("Accept", "image/*");
    async = www.Send();
    while (!async.isDone)
        yield return null;
    if (www.isError)
    {
        Debug.Log(www.error);
    }
    else
    {
        //yield return null; // This<-------------------
        yield return new WaitForEndOfFrame();  // OR This<-------------------
        tex = DownloadHandlerTexture.GetContent(www);   
    }
    

    虽然,我不知道这有多可靠。除非进行彻底的测试,否则我不会在商业产品中使用它。

    一个可靠的解决方案是提交关于www.isDone 的错误,然后不要使用www.isDone。使用yield return www.Send(); 直到解决此问题。

    UnityWebRequest www = UnityWebRequest.GetTexture("https://0.gravatar.com/avatar/fc2beef90fad49f83d79650a10b5c030?s=256&d=identicon&r=G");
    www.SetRequestHeader("Accept", "image/*");
    yield return www.Send(); // This<-------------------
    
    if (www.isError)
    {
        Debug.Log(www.error);
    }
    else
    {
        tex = DownloadHandlerTexture.GetContent(www);    
    }
    

    【讨论】:

    • 您是否尝试过您的解决方案?我使用相同的模式来读取一些 json 数据并且它工作得很好 - 所以它只会在纹理加载时中断?今晚晚些时候我会试试你的解决方案并报告
    • 我认为您没有阅读答案。 “当 www.isDone 或 async.isDone 与 DownloadHandlerTexture 一起使用时会发生这种情况”。它发生在纹理上,但不会发生在文本数据上。问题是isError 在未完成时报告已完成。最好在尝试答案之后再制作 cmets 以节省我们双方的时间。
    • 我明白了答案,我很惊讶它只在 DownloadHandlerTexture 上中断。
    • 哦,好的。UnityWebRequest 大约 9 个月大,还是新的。还有很多要修复的。回家后尝试一下,并提交错误报告。我没有时间这样做。
    • 刚刚验证了您的修复并且它有效。将制作一个示例项目以将错误提交给 Unity。 ty
    猜你喜欢
    • 2021-07-24
    • 1970-01-01
    • 2023-04-04
    • 2018-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多