I don't know why that error is getting thrown, but here is a solutions that works.
Color[] animationData = new Color[1];
animation.GetData<Color>(0,new Rectangle(0,0,1,1),c, 0, 1);
We are creating a 1x1 rectangle, and only sampling data from that.
update
Ok, I have had some time you look into this more, and I think there may be a bug in the framework. When you are doing Texture2D.GetData<T>(T[] data, int start, int length)
it is just an overload for Texture2D.GetData<T>(int level, Rectangle? rect, T[] data, int start, int length)
and passes in null for the rectangle. If you manually do that (ie. pass in null instead of the 1x1 rectangle) you get the same error.
Now, follow the chain down, and it eventually calls
private unsafe void CopyData<T>(int level, Rectangle? rect, T[] data, int startIndex, int elementCount,...)
This method is way to long to post here (over 220 lines of code in ILSpy), and since I don't have the whole picture it is hard to figure out. However, this little bit is interesting.
tagRECT* ptr2 = null;
Rectangle rectangle = default(Rectangle);
if (rect.HasValue)
{
rectangle = rect.Value;
ptr2 = ref rectangle;
if (ptr2 != null)
{
*(int*)(ptr2 + 8 / sizeof(tagRECT)) = *(int*)(ptr2 + 8 / sizeof(tagRECT)) + *(int*)ptr2;
*(int*)(ptr2 + 12 / sizeof(tagRECT)) = *(int*)(ptr2 + 12 / sizeof(tagRECT)) + *(int*)(ptr2 + 4 / sizeof(tagRECT));
}
}
See how ptr2
is only defined if you passed in a value for the rectangle? Further down the trail (if I followed the correct code path)
num5 = <Module>.D3DXLoadSurfaceFromSurface(ptr3, null, (tagRECT*)ptr2, ptr5, null, (tagRECT*)ptr2, 1, 0);
and then later we are doing some recursion based on if num5>=0
. Which recursive cal is actually determined on some other logic I haven't worked out, but I don't think that part matters...famous last words, right? :)
So all that to say this, I don't think that the Rectangle passed is is supposed to be null. A few places in the code it looks like they are trying to force the rectangle to have a value of the texture size. Perhaps it isn't working.
Take all of that with several grains of salt. I am in not way qualified as a low level GFX programmer. Maybe someone else here can answer for certain.
SurfaceFormat.Color
(from memory). \$\endgroup\$