Hi,
I’m trying to use BackgroundWorker to preproses my 2D png grapichs. I do this for runtime atlassing based upon GL.MAX_TEXTURE_SIZE and making Pixel coliders. This works on Windows but on Android the RunWorkerCompletedEventHandler() is fired premature because of the following exception.
System.InvalidOperationException: Operation not called on UI thread. at Microsoft.Xna.Framework.Threading.EnsureUIThread () [0x00007] in <8335ffb25c73411d8c018e841c87a942>:0 at Microsoft.Xna.Framework.Graphics.Texture2D.PlatformGetData[T] (System.Int32 level, System.Int32 arraySlice, Microsoft.Xna.Framework.Rectangle rect, T[] data, System.Int32 startIndex, System.Int32 elementCount) [0x00000] in <8335ffb25c73411d8c018e841c87a942>:0 at Microsoft.Xna.Framework.Graphics.Texture2D.GetData[T] (System.Int32 level, System.Int32 arraySlice, System.Nullable
1[T] rect, T[] data, System.Int32 startIndex, System.Int32 elementCount) [0x00011] in <8335ffb25c73411d8c018e841c87a942>:0
at Microsoft.Xna.Framework.Graphics.Texture2D.GetData[T] (System.Int32 level, System.Nullable1[T] rect, T[] data, System.Int32 startIndex, System.Int32 elementCount) [0x00000] in <8335ffb25c73411d8c018e841c87a942>:0 at Microsoft.Xna.Framework.Graphics.Texture2D.GetData[T] (T[] data) [0x0000e] in <8335ffb25c73411d8c018e841c87a942>:0 ...
Notice: Threading.EnsureUIThread, And It is NOT on the UI thread. Yet, LoadFromStream() does not trigger.! (So settings it seems fine, but getting it is a big no-no). Also Windows does mind me doing this. I have not tested Mac or IOS yet.
I’m not drawing or doing anything particular interesting when this happens. Basically I need a way to pre-process my PNG images on runtime. I can do this on the main (UI) thread, but then no cool progress indicator
I’m targeting: Windows, Windows Store, Android, Mac, IOS. System.Drawing - which was my first choice - is not supported everywhere, so i’m using. FromStream, GetData, SetData to play around with the pixels.
Anyone has any ideas on this…? Thanks!
EDIT: Both Mac and IOS give the same behavior. I’m assuming that its a OpenGL directive. So you cant use GetData, and probably not SetData on a separate thread on other targets then Windows or Windows Store.