Graphics.DrawTexture on RenderTexture draws twice (sometimes)

I’m having a hard time getting my RenderTexture to work. The idea is simple enough. The camera just shows a plane. I now create a RenderTexture at Startup and set the material.texture of the plane to my newly created RenderTexture. On Update I draw another texture (brush) into the RT. The good new is that it works. Unfortunately sometimes the brush is drawn “twice” AND it is drawn at a another position and in a different scale. This does not happen all the time. If I delay my draw calls significantly (i.e. 1 per second) it can be that 3 times the brush is drawn at the wanted position, the fourth time the effect described above happens. It is not predictable.

renderTexture = new RenderTexture(1024, 1024, 0, RenderTextureFormat.ARGB32);
canvas.renderer.material.mainTexture = renderTexture;

In Update() I basically do this:

RenderTexture.active = renderTexture;
Graphics.DrawTexture(new Rect(400, 200, 128, 128), brush);
RenderTexture.active = null;

I never Release() the RT by the way. A check before drawing shows that renderTexture.IsCreated() is always true. The behaviour is observed in the Unity IDE Windows 3.4.2.

I’m running out of ideas now. Any help appreciated.

Ben

I tried to understand leftBorder etc properties of Graphics.DrawTexture() because it is mentioned “Number of pixels from the left that are not affected by scale.” and if I play around with them I get similiar looking effects. But the documentations says nothing about those properties and how to use them.

Well, but this is a sidenote and has most likely nothing to do with the above.

A “Too many rootsets” Editor crash came to my rescue. This kind of stuff you can’t make up. After restarting and rerunning the scene the “ghost” draws have disappeared. There must have been some texture memory lingering on or something like this. I would like to file a bug but unfortunately I can’t reproduce it.

Reminds me of those “have you rebooted your Windows” advices :slight_smile:

Ben