Search Unity

Question How not to crash when Texture2D.CreateExternalTexture is invalid ?

Discussion in 'General Graphics' started by narf03, Nov 7, 2022.

  1. narf03

    narf03

    Joined:
    Aug 11, 2014
    Posts:
    223
    I am trying to create Texture from native plugin.

    Currently unity will always crash whenever i do Texture2D.CreateExternalTexture, maybe because of the address is wrong or something wrong with the texture. I wonder if there is a way(code) in unity to check and see if the texture/address is valid or not instead of just crashing directly ?
     
  2. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    675
    I doubt it. When you go to native land, it's your responsibility to check those things.

    Are you sure you are passing the right type and are you sure your texture is not null?

    As the documentation says, the type needs to be

    • [B]D3D11[/B]: ID3D11ShaderResourceView* or ID3D11Texture2D*
    • [B]D3D12[/B]: ID3D12Texture2D*

    For [B]OpenGL[/B]/[B]OpenGL ES[/B], the nativeTex parameter is a GLuint.

    For [B]Metal[/B], the nativeTex parameter is an id<MTLTexture>.

    For [B]Vulkan[/B], the nativeTex parameter is a VkImage*.


    For example, if you are using OpenGL, you can call glIsTexture to check if the handle is a valid texture.
     
  3. narf03

    narf03

    Joined:
    Aug 11, 2014
    Posts:
    223
    thats something i do not know, as i said, im trying to do it ... i manage to get some example code on the net that will generate texture using opengl, im trying to plug that in, generate texture using the plugin, pass the texture handle back into unity and use that to create texture within unity. I do not know how to inspect the gpu memory to see if they are null, i can only keep trying until it stop crashing.