Game fails to resume - garbage collection issue

[EDIT]
Since it seems that updating to the latest version of Xamarin Android has altered the nature of this problem, I’ve edited this thread appropriately.

The problem I’m now getting consistently is that described in my second post below: whenever I hit the home button while my game is running, then try to restart, the game hangs during the resume process with a continual sequence of GC_OLD_BRIDGE and GC_MINOR log messages in debug build following the GraphicsDevice.ResetClientBounds log entry (release build just hangs).

This can be replicated in the following manner:

  • In Visual Studio 2010, create a new Windows Phone 7.1 project (to get
    the empty Game1 class).
  • In Xamarin studio, create a new Android application.
  • From Monogame 3.2, add the Lidgren and Monogame.Android projects to
    the solution
  • Add references to OpenTK, Lidgren and Monogame.Android in the project
    created by the solution.
  • Set minimum Android version for the project created by the solution
    to 2.2 in the project options
  • Add a link to the Game1.cs file created by the VS new project
  • Update MainActivity.cs as below:

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Microsoft.Xna.Framework;

namespace [your app namespace]
{
    [Activity (Label = “TSTest2”, MainLauncher = true, Icon = “@drawable/icon”)]
    public class MainActivity : AndroidGameActivity
    {
        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);
            FrameLayout Layout = new FrameLayout(this);
            Game1.Activity = this;
           Game1 game = new Game1();
            Layout.AddView(game.Window);
            SetContentView (Layout);
            game.Run();
        }
    }
}

  • Run the application (should get the blue screen)
  • Hit the Home button
  • Find and tap on the application’s icon to restart

The application will now hang while trying to resume. This was tested on a Samsung Galaxy S running Gingerbread.

Okay, so I updated everything to the latest versions - unfortunately, this has mde things worse:
Attempting to resume in debug mode now causes the game to hang, with a series of log entries along the lines of the following:

[Mono] GC_OLD_BRIDGE num-objects 31 num_hash_entries 31 sccs size 31 init 0.00ms df1 0.17ms sort 0.01ms dfs2 0.37ms setup-cb 0.04ms free-data 4.25ms links 0/0/0/0 dfs passes 62/31
[Mono] GC_MINOR: (Nursery full) pause 81.29ms, total 81.58ms, bridge 39.98ms promoted 848K major 1056K los 2228K
[Mono] GC_OLD_BRIDGE num-objects 31 num_hash_entries 31 sccs size 31 init 0.00ms df1 0.17ms sort 0.01ms dfs2 0.37ms setup-cb 0.04ms free-data 4.25ms links 0/0/0/0 dfs passes 0/0
[Mono] GC_MINOR: (Nursery full) pause 79.61ms, total 79.95ms, bridge 0.13ms promoted 448K major 1504K los 2228K
[Mono] GC_OLD_BRIDGE num-objects 1 num_hash_entries 1 sccs size 1 init 0.00ms df1 0.17ms sort 0.01ms dfs2 0.12ms setup-cb 0.01ms free-data 0.06ms links 0/0/0/0 dfs passes 2/1
[Mono] GC_MINOR: (Nursery full) pause 82.12ms, total 82.43ms, bridge 18.93ms promoted 448K major 1952K los 2228K
[Mono] GC_OLD_BRIDGE num-objects 1 num_hash_entries 1 sccs size 1 init 0.00ms df1 0.17ms sort 0.01ms dfs2 0.12ms setup-cb 0.01ms free-data 0.06ms links 0/0/0/0 dfs passes 0/0
[Mono] GC_MINOR: (Nursery full) pause 81.40ms, total 81.69ms, bridge 0.13ms promoted 448K major 2400K los 2228K

  • this follows directly after [MonoGame] GraphicsDeviceManager.ResetClientBounds: newClientBounds={X:0 Y:0 Width:480 Height:800} in the log.

I tried adding a “NoHistory = true” attribute to my activity, but that just resulted in another crash on resume - the “MakeCurrent” call in AndroidGameWindow.Onload throws an error.

I’m using Monogame 3.2 and the latest version of Xamarin Android.

Okay, ran some tests last night.

Galaxy S/Android 2.3.3:
Both my game and the test app detailed above lock with GC errors on resume

Nokia X/Android 4.1.2:
Both my game and the test app resume correctly. However, following a resume, my game is throwing an error on exit in SpriteBatch.Setup (gd == null).

Android 15 & 17 Emulator:
My game failed completely to resume, not even getting the GC errors - I’m guessing that this is due to the size of the game and the amount of content it has, plus the emulator being dog-slow. Test app resumes correctly.

Since the Nokia X has less memory than the Galaxy, I’m guessing that this is specific to older Android versions, but just don’t have the hardware to confirm.

Are you running the latest MonoGame build from develop?

I seem to remember similar errors from older MG versions.

I am now! Been working with the team and we managed to get things up and running last night.

I’ve got to test on a few more devices, but I’m confident that this is fixed.