Two issues about the Native Texture in WP8

I want to use the Native Texture in WP8 (Unity 4.3.4),
I have created an texture in the native code, and use Texture2D.CreateExternalTexture to use this texture in Unity.
but the big issue is how to release the texture:

  • it look like the “UnityEngine.Object.Destroy(theTexure)” does not release the real texture, in my test, the program would crash because of low memory.
  • if I called the ID3D11Texture2D->Release and ID3D11ShaderResourceView->Release in the Native Code when release the texture,
    the Program will crash later at
    D3D11.DLL!CContext::ID3D11DeviceContext1_SetShaderResources_<5,4>(struct ID3D11DeviceContext1 *,unsigned int,unsigned int,struct ID3D11ShaderResourceView * const *) it seems that the Unity continue use the texture after it has been released, I have tried to delay 10 frames to call the native release function, but that won’t fix the issue.

there is also another issue about the Native Texture:
When the App return from pause, the ID3D11Device seems need to be recreated, and the Native Texture should also be recreated, in my program, I just recreated the texture in native code and use Texture2D.UpdateExternalTexture to update the unity Texture, it seems work mostly, but some time the program crash…

so here are my two issues:

  • how to release the native created texture in unity,
  • how to deal with the native texture when the app returned from pause.

Any One knows how to resolve them?

Thank you!

From a quick look at this it looks like you should destroy the Texture2D object and then release the native texture. I don’t know for sure, where you have to make sure texture is not used for anything. In general it shouldn’t be different from standalone player, so you might experiment with that.
As with pause/resume it might be a bug. I think you should fill a bug report, so we could do deeper investigation.

Thanks for the reply.

I change some code in destroy the Texture2D, and the native texture can be released now.

and about the pause/resume bug, I’m not sure about how to reproduce it now, it just appeared randomly, it seems like a memory write-overflow issue. I’ll try to get more information about this issue.