Texture.GetNativeTexturePtr sometime returns 0

In my tool, I generate many RenderTextures.
I facing a probrem at runtime program built by Unity 2019.1.5f1.

Some of textures seems to be not usable. I did a lot of researches, I found Texture.GetNativeTexturePtr() returns 0 about unusable texture when only runtime.

I check with following

var texture = new RenderTexture(width, height, depth, format);
texture.enableRandomWrite = true;
// log to external file
AddLog($"New RenderTexture Create ({texture.GetNativeTexturePtr()});");
AddLog($"Is Created: {texture.Create()}");
AddLog($"New RenderTexture Created ({texture.GetNativeTexturePtr()});");

The some result is seems good like that:

New RenderTexture Create (0);
Is Created: True
New RenderTexture Created (2679896030752);

But some result remains 0:

New RenderTexture Create (0);
Is Created: True
New RenderTexture Created (0);

This problem is not occurred in unity editor. By runtime, some environments occur and some do not. Each machines are windows10.

Please help me if you know anything about it.

I try to use CustomRenderTexture instead of RenderTexture, Texture.GetNativeTexturePtr always returns non-zero value.

I think that it must not correct solution…

I’m going to wait and see…

—add 11/27/2020

The problem has caused again.

For now, I fixed like following, I can’t do anything else. It may return a non-zero value If generate many times.

if (texture.GetNativeTexturePtr().ToInt64() == 0) {
    const int TrialCount = 100000;
    int count = 0;
    do {
        System.Threading.Thread.Sleep(1);

        texture.Release();
        texture= new CustomRenderTexture(width, height, format);
        texture.enableRandomWrite = true;
        texture.Create();

    } while ((texture.GetNativeTexturePtr().ToInt64() == 0) && (++count < TrialCount));
}

Cap must have retired but that doesn’t mean the world will stay without a superhero. The job is on your shoulders now, so, hurry up and let’s get done with this task by gearing up in the Captain America Costume designed by J4Jacket now.