How to create a Texture2D without corrupting video memory?

Viewed 32

In Monogame, I'm creating a 2D texture that's a horizontal flip of an existing texture using GetData and SetData like this:

    private static Texture2D Flip(Texture2D art)
    {
        Color[] oldData = new Color[art.Width * art.Height];
        art.GetData(oldData);

        Texture2D newTexture = new Texture2D(Root.Graphics.GraphicsDevice, art.Width, art.Height);
        Color[] newData = new Color[art.Width * art.Height];
     
        // Edit newData using oldData

        newTexture.SetData(newData);
        return newTexture;
    }

This seemed to work on Windows but when running it on Android, although the flip itself works, some other, seemingly random and unrelated, texture gets corrupted: it becomes an amalgam of several textures and partially vertically flipped.

I suspect that my call to SetData somehow overwrites another region of memory or something.

How can I create programatically a new texture without this corruption happening?

0 Answers
Related