Search Unity

Video CreateExternalTexture - error - nativeTex can not be null

Discussion in 'Audio & Video' started by littlstarsunny, Nov 27, 2017.

  1. littlstarsunny

    littlstarsunny

    Joined:
    Apr 12, 2017
    Posts:
    7
    I recently updated to Unity 2017 and now the following line is failing:

    SurfaceTexture = Texture2D.CreateExternalTexture(DEFAULT_SURFACE_WIDTH, DEFAULT_SURFACE_HEIGHT, TextureFormat.RGBA32, true, false, IntPtr.Zero);

    The error is: ArgumentException: nativeTex can not be null

    So it seems that I can no longer pass IntPtr.Zero as the last argument in CreateExternalTexture.

    Does anyone know what I should be doing instead? For context, this is for the Android Platform

    Thanks!
    Sunny
     
  2. littlstarsunny

    littlstarsunny

    Joined:
    Apr 12, 2017
    Posts:
    7
    I fixed it by creating a texture2d with same attributes and passing it into CreateExternalTexture as a native pointer

    Code (CSharp):
    1. Texture2D tex = new Texture2D(DEFAULT_SURFACE_WIDTH, DEFAULT_SURFACE_HEIGHT, TextureFormat.RGBA32, true, false);        
    2. IntPtr texPtr = tex.GetNativeTexturePtr();
    3. SurfaceTexture = Texture2D.CreateExternalTexture(DEFAULT_SURFACE_WIDTH, DEFAULT_SURFACE_HEIGHT, TextureFormat.RGBA32, true, false, texPtr);
     
  3. ZhengzhongSun

    ZhengzhongSun

    Joined:
    Oct 12, 2016
    Posts:
    20
    I use Unity 2018.2.0f2, but It seems the unity editor will crash when createExternalTexture.
     
  4. PyroIZO

    PyroIZO

    Joined:
    Sep 23, 2015
    Posts:
    4
    Old thread, but same crash on Unity 2019.2.3f1

    Does someone have a solution to copy the native pointer from a Texture2D to another ?
     
  5. ajoeldho

    ajoeldho

    Joined:
    Nov 22, 2019
    Posts:
    1
    Does anyone have any solution for this?
     
  6. EvgenyVasilyev

    EvgenyVasilyev

    Joined:
    Jul 5, 2019
    Posts:
    7
    Crashes in 2019.2.12f1 as well :(