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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Graphics.CopyTexture() Crash on some android mobiles

Discussion in 'General Graphics' started by mensaoliang, Sep 26, 2018.

  1. mensaoliang

    mensaoliang

    Joined:
    Jul 10, 2017
    Posts:
    9
    What I am trying to do is combine their meshes, materials (with same shader and properties except mainTex) and textures all into one, so that I can draw the render, outline and shadow in 3 drawcalls, otherwise it takes 18 drawcalls for each character.

    It works pretty good on PC, IOS and some new Android devices. However, I found Graphics.CopyTexture() will cause crash on some android devices, usually mobiles using PowerVR GPU before 2017.

    Here is what my code like:
    Code (CSharp):
    1.  
    2.             Texture2D combinedTexture = new Texture2D(dstWidth, dstHeight, format, false);
    3.             int gridSzie = textureBuffer[textureBuffer.Count - 1].width;
    4.             Vector2 gridFrame = new Vector2(dstWidth / gridSzie, dstHeight / gridSzie);
    5.             for (int i = 0; i < textureBuffer.Count; i++)
    6.             {
    7.                 var gridFill = new Vector2(textureBuffer[i].width / gridSzie, textureBuffer[i].height / gridSzie);
    8.                 var offset = FillGrid(gridFill, gridFrame);
    9.                 Graphics.CopyTexture(textureBuffer[i], 0, 0, 0, 0, textureBuffer[i].width, textureBuffer[i].height,
    10.                     combinedTexture, 0, 0, (int)(offset.x * gridSzie), (int)(offset.y * gridSzie));
    11.                 var uvOffset = new Vector2(offset.x / gridFrame.x, offset.y / gridFrame.y);
    12.                 var uvScale = new Vector2(gridFill.x / gridFrame.x, gridFill.y / gridFrame.y);
    13.                 foreach (var item in textureIndexCache[i])
    14.                 {
    15.                     uvInfoCache[item] = new UVInfo(uvOffset, uvScale);
    16.                 }
    17.             }
    18.  
    BTW, I checked SystemInfo.copyTextureSupport == UnityEngine.Rendering.CopyTextureSupport.None, it returns false.

    If I commit Graphics.CopyTexture line, it won't crash. So is there some thing wrong with my code? Is there any other way to avoid Graphics.CopyTexture and copy several compressed textures into one compressed or uncompressed texture? I think the memory consumption is acceptable for this case.
     
  2. mensaoliang

    mensaoliang

    Joined:
    Jul 10, 2017
    Posts:
    9
    BTW, I only find it crashes on two mobile, and there GPU is all Imagination PowerVR G6200.
     
  3. mensaoliang

    mensaoliang

    Joined:
    Jul 10, 2017
    Posts:
    9
    When I tried to check the SystemInfo.copyTextureSupport via Debug.Log(SystemInfo.copyTextureSupport.ToString()), I got output like that: Basic, Copy3D, DifferentTypes, TextureToRT, RTToTexture. Why a single enum has multiple values? How could I do that?
     
  4. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,836
    Please submit a bug report.

    Make the enum values powers of two.
     
  5. mensaoliang

    mensaoliang

    Joined:
    Jul 10, 2017
    Posts:
    9
    Thanks