Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MonoGame Windows 8 - WriteableBitmap

If you place the following code in the game loop (Update or Draw) of a MonoGame app (can just be the default project template):

new Windows.UI.Xaml.Media.Imaging.WriteableBitmap(150, 150);

It throws a cross-thread error...

The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))

So then I tried this:

var dispatcher = Windows.UI.Core.CoreWindow.GetForCurrentThread().Dispatcher;
dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, delegate
{
     new Windows.UI.Xaml.Media.Imaging.WriteableBitmap(150, 150);
});

Same error.

Looking under the covers, it doesn't look like MonoGame runs the game loop on a background thread or anything. It uses a synchronous loop.

Any ideas of a way to use WriteableBitmap in MonoGame? (I need to use it to render out some live tiles)

like image 430
jonathanpeppers Avatar asked Aug 21 '26 04:08

jonathanpeppers


1 Answers

If you're using the Game class then your creating an application that by default does not support XAML.

Currently the best way to support XAML in a MonoGame app is to use the Siverlight-style XNA game as outlined in this thread...

http://monogame.codeplex.com/discussions/359544

like image 54
Tom Spilman Avatar answered Aug 23 '26 17:08

Tom Spilman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!