Texture2D.GetData / SetData Working Strangely

Hi,

I am writing some code to get around the annoying issue of references to RenderTarget2D objects being lost when an Android app is sent to the background. What I am trying to do is cache the raw data for these offscreen images when the app is sent to background using RenderTarget2D.GetData and then recreate them when the app is sent to the foreground using RenderTarget2D.SetData.

This is all kind of working apart from when the texture is recreated with SetData the colours are going all weird like the byte order has been changed or something. if I do the Get/Set process again on recreation it flips everything back to normal and things look fine!

Is this a bug or something I am doing wrong? My render targets are created with SurfaceFormat.Color so I’m guessing UInt32 is the correct format to use for storing the data here? The code is roughly analogous to this kind of thing…

UInt32[] data;

// on pause
data	= new UInt32[ texture.Width*texture.Height  ];
texture.GetData<UInt32> (data);

// on resume
// first recreate the texture and then...
texture.SetData<UInt32>	(data);

// all looks weird unless I add this again...
texture.GetData<UInt32> (data);
texture.SetData<UInt32>	(data);

Any help appreciated…

cheers

Something else problematic I have noticed is that after repeatedly sending the app to background and returning it to foreground I start to lose the GL context on recreated textures even if I appear to have recreated them properly. This is also the case with Texture2D objects created using LoadContent (ie when MonoGame is handling the recreation of the texture).

I don’t know if it’s anything to do with it but I noticed in the logs that each time I send the app to background and resume the following piece of output in the logs (which only appears once when the app is first launched) is duplicated for each background/foreground cycle, so you end up with this piece of output repeated many, many times which doesn’t seem right…

[MonoGame] Supported extensions:
[MonoGame] GL_OES_EGL_image
[MonoGame] GL_OES_depth24
[MonoGame] GL_OES_depth32
[MonoGame] GL_OES_element_index_uint
[MonoGame] GL_OES_texture_float
[MonoGame] GL_OES_texture_float_linear
[MonoGame] GL_OES_compressed_paletted_texture
[MonoGame] GL_OES_compressed_ETC1_RGB8_texture
[MonoGame] GL_OES_depth_texture
[MonoGame] GL_OES_texture_half_float
[MonoGame] GL_OES_texture_half_float_linear
[MonoGame] GL_OES_packed_depth_stencil
[MonoGame] GL_OES_vertex_half_float