Monogame for Windows phone 8 doesn't draw on resume (if using additional xaml pages)

I’m creating a graphing calculator app and I need a lot of gamepage to xaml page navigation. It all works except when I try going out of the app and then resume. Resuming even works fine if you don’t have additional xaml pages (i.e. if you haven’t navigated from and back to the gamepage), but if you have some it just doesn’t want to draw user primitives (spritebatch does work).

Here I made a test app: https://www.dropbox.com/s/fk1tymr1hsyroqh/MonoTemplate.zip

Now, in emulator, when you navigate to gamepage and back and try going out and then back into the app it will crash. On a device, It doesn’t crash, just doesn’t render the triangle. Spritebatch obviously still works!
(I am aware that some stuff in the test app are not as optimized as possible, like creating new basic effect every frame and such…)

EDIT: The error thrown when debugging in emulator is
“A first chance exception of type ‘System.TypeLoadException’ occurred in SharpDX.DLL
Additional information: Could not find Windows Runtime type ‘SharpDX.WP8.Interop’.”

On the GraphicsDevice.DrawUserPrimitives(); line

I have done some more research and it seems that the GraphicsDevice gets suspended:

A first chance exception of type 'SharpDX.SharpDXException' occurred in SharpDX.DLL
Additional information: HRESULT: [0x887A0005], Module: [SharpDX.DXGI], ApiCode: [DXGI_ERROR_DEVICE_REMOVED/DeviceRemoved], Message: The GPU device instance has been suspended. Use GetDeviceRemovedReason to determine the appropriate action.

But this happens only if you navigate between pages! If you don’t, this does not happen. Any solutions for this?

I guess you are using a fairly old version of MonoGame that dosn’t support resuming on WP8 yet. I recommend building MonoGame yourself from github. Also, it seems that the reference to SharpDX.WP8.winmd is missing (which was missing in old MonoGame versions).

1 Like

Oh no, It works fine if I don’t use xaml pages other than the GamePage. I am using v3.2, which does support resume as far as I know.

EDIT: I tried now changing navigation code so it doesn’t go to new GamePage but rather go back to it, and now it works! So instead of:

NavigationService.Navigate(new System.Uri("/GamePage.xaml", System.UriKind.Relative));

I set it to

NavigationService.GoBack();

Am I even allowed to initialize Game.cs multiple times?

Well, if you wanto to you can, but it’s probably better to keep one instance of your game and then change levels in that one.

That will sort of be a problem because I based my app on multiple instances of Game classes… Looks like I have some redesigning to do…

Have you had any luck with this? I am currently trying to work through what I think is the same issue.
Edit: I mean without re-writing and using the go back like in hybrid silverlight/xna apps. I am now going through the process of re-writing I guess now too ! :\

Nope, I just went with one game class (gamepage) to rule them all… It even worked out better than expected! But I know that in most cases it wont be that easy.

I think you need to use Dispatcher to navigate between normal pages and game page. Like this :

this.Dispatcher.BeginInvoke(()=>
{
   NavigationService.Navigate(new Uri("/GamePage.xaml", UriKind.Relative));
});