GL Error with Xamarin 4 and (possibly) the latest MG source

I updated my Android game project to work with the Xamarin 4 update. After that, every time when I want to enter a level from the menu screen of the game, a Microsoft.Xna.Framework.Graphics.MonoGameGLException will be thrown:

In MonoGame.Framework\Graphics\Shader\ConstantBuffer.OpenGL.cs, line 83: GraphicsExtensions.CheckGLError();
“GL.GetError() returned InvalidOperation”

Below is the call stack:

System.Diagnostics.Debugger.Mono_UnhandledException_internal() in 
System.Diagnostics.Debugger.Mono_UnhandledException( Parameters) in /Users/builder/data/lanes/2098/3efa14c4/source/mono/mcs/class/corlib/System.Diagnostics/Debugger.cs:122
object.8abf2db8-f0ff-4585-9629-b9928272f607( Parameters) in 
Microsoft.Xna.Framework.Graphics.ConstantBuffer.PlatformApply( device,  program) in i:\MonoGame\MonoGame.Framework\Graphics\Shader\ConstantBuffer.OpenGL.cs:83
Microsoft.Xna.Framework.Graphics.ConstantBufferCollection.SetConstantBuffers( Parameters) in i:\MonoGame\MonoGame.Framework\Graphics\Shader\ConstantBufferCollection.cs:74
Microsoft.Xna.Framework.Graphics.GraphicsDevice.PlatformApplyState( Parameters) in i:\MonoGame\MonoGame.Framework\Graphics\GraphicsDevice.OpenGL.cs:861
Microsoft.Xna.Framework.Graphics.GraphicsDevice.ApplyState( Parameters) in i:\MonoGame\MonoGame.Framework\Graphics\GraphicsDevice.cs:420
Microsoft.Xna.Framework.Graphics.GraphicsDevice.PlatformDrawUserIndexedPrimitives<Microsoft.Xna.Framework.Graphics.VertexPositionColorTexture>( Parameters) in i:\MonoGame\MonoGame.Framework\Graphics\GraphicsDevice.OpenGL.cs:933
Microsoft.Xna.Framework.Graphics.GraphicsDevice.DrawUserIndexedPrimitives<Microsoft.Xna.Framework.Graphics.VertexPositionColorTexture>( Parameters) in i:\MonoGame\MonoGame.Framework\Graphics\GraphicsDevice.cs:1006
Microsoft.Xna.Framework.Graphics.SpriteBatcher.FlushVertexArray( Parameters) in i:\MonoGame\MonoGame.Framework\Graphics\SpriteBatcher.cs:292
Microsoft.Xna.Framework.Graphics.SpriteBatcher.DrawBatch( Parameters) in i:\MonoGame\MonoGame.Framework\Graphics\SpriteBatcher.cs:226
Microsoft.Xna.Framework.Graphics.SpriteBatch.End( Parameters) in i:\MonoGame\MonoGame.Framework\Graphics\SpriteBatch.cs:116
MyGame.PhoneMenuScreen.Draw( Parameters) in i:\MyGame_Android\Screens\PhoneMenuScreen.cs:299
MyGame.ScreenManager.Draw( Parameters) in i:\MyGame_Android\ScreenManager\ScreenManager.cs:925
Microsoft.Xna.Framework.Game.<.cctor>b__18( Parameters) in i:\MonoGame\MonoGame.Framework\Game.cs:561
Microsoft.Xna.Framework.Game.SortingFilteringCollection<Microsoft.Xna.Framework.IDrawable>.ForEachFilteredItem<Microsoft.Xna.Framework.GameTime>( Parameters) in i:\MonoGame\MonoGame.Framework\Game.cs:853
Microsoft.Xna.Framework.Game.Draw( Parameters) in i:\MonoGame\MonoGame.Framework\Game.cs:566
MyGame.GameStateManagementGame.Draw( Parameters) in i:\MyGame_Android\Program.cs:152
MyGame.Game1.Draw( Parameters) in i:\MyGame_Android\Game1.cs:89
Microsoft.Xna.Framework.Game.DoDraw( Parameters) in i:\MonoGame\MonoGame.Framework\Game.cs:683
Microsoft.Xna.Framework.Game.Tick( Parameters) in i:\MonoGame\MonoGame.Framework\Game.cs:515
Microsoft.Xna.Framework.AndroidGameWindow.OnUpdateFrame( Parameters) in i:\MonoGame\MonoGame.Framework\Android\AndroidGameWindow.cs:86
OpenTK.GameViewBase.OnUpdateFrame( Parameters) in /Users/builder/data/lanes/2098/3efa14c4/source/opentk/Source/OpenTK/Platform/Android/GameViewBase.cs:313
OpenTK.Platform.Android.AndroidGameView.UpdateFrameInternal( Parameters) in /Users/builder/data/lanes/2098/3efa14c4/source/opentk/Source/OpenTK/Platform/Android/AndroidGameView.cs:349
OpenTK.Platform.Android.AndroidGameView.RunIteration( Parameters) in /Users/builder/data/lanes/2098/3efa14c4/source/opentk/Source/OpenTK/Platform/Android/AndroidGameView.cs:569
OpenTK.Platform.Android.AndroidGameView.StartThread.AnonymousMethod__0( Parameters) in /Users/builder/data/lanes/2098/3efa14c4/source/opentk/Source/OpenTK/Platform/Android/AndroidGameView.cs:459
Android.App.SyncContext.Send.AnonymousMethod__0( Parameters) in /Users/builder/data/lanes/2098/3efa14c4/source/monodroid/src/Mono.Android/src/Android.App/SyncContext.cs:32
Java.Lang.Thread.RunnableImplementor.Run( Parameters) in /Users/builder/data/lanes/2098/3efa14c4/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:36
Java.Lang.IRunnableInvoker.n_Run( Parameters) in /Users/builder/data/lanes/2098/3efa14c4/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Java.Lang.IRunnable.cs:71
object.639b1e2a-3066-4ebc-be6b-30af0f8469aa( Parameters) in 

This error only shows up in the Android version as I have confirmed that the WP8 version is working well, so most probably it is not my code that is causing this error… Can someone help explain what the issue is?

Weird thing is this error only shows up on my Nexus 4… On my Nexus 6 everything runs smoothly :confused:

Edit: On Nexus 6 only the debug build works. On both Nexus 4 and Nexus 6 the release build will force quit right after being launched. Not sure if this is a Xamarin issue or a MG issue…

Edit 2: I just reset MG source back to the version on 10/11/2015 (SHA-1: d13b3ada196701944a3887fe9a5d6c1abb88864e) and now the debug build can run on Nexus 4. Unfortunately the release build still keep force-quitting on both Nexus 4 and Nexus 6…

go to your .csproj file, open it in wordpad, look for everywhere it says release and debug. compare what’s different about them and you should have no problem fixing the error. THE ONLY thing that really changes between release and debug are compiler directives that are specified in that file so if debug works it shouldnt be an issue of the MG library itself.

Xamarin 4 has not been a smooth upgrade on Android for me either. Firstly it would lock up VS 2013 and VS 2015 when loading an existing solution file, requiring a task kill to get out of it. I only had Xamarin for Visual Studio installed. I repaired, uninstalled, reinstalled, to no avail. I guessed it must have been something with the existing solution or project files. Ended up uninstalling and installing the full Xamarin suite and loading the solution in Xamarin Studio. This worked (loads, builds, deploys and runs), and it must have done something to the solution and/or project files because now it loads in VS 2015. But it doesn’t build. Complains about the MonoGame project not finding the required information in a lock file, and making sure MonoAndroid,Version=v6.0 is mentioned in the targets.

When I had it deploying and running from Xamarin Studio, I also had the issue of it force quitting in a release build. I found that in the project properties, it had deselected all supported architectures in the Release configuration. I got this hint when looking at the logcat output and it mentioned the device architecture was not supported in the apk. I re-selected all the required architectures and it launched. This was also after uninstalling the Debug build because trying to deploy the Release build resulted in a deployment failed error.

So I’m not surprised there may be other issues with Xamarin 4. It seems to be one of those upgrades.

Hi @Damien_James_Gibson I don’t think the problem is on my side. The only parts that contain “debug” and “release” are listed below:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE;ANDROID</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <EmbedAssembliesIntoApk>False</EmbedAssembliesIntoApk>
    <JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
    <AndroidLinkMode>None</AndroidLinkMode>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE;ANDROID</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <DebugType>full</DebugType>
    <JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
    <AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
    <AndroidSupportedAbis>armeabi;armeabi-v7a;x86;arm64-v8a;x86_64</AndroidSupportedAbis>
  </PropertyGroup> 

As you can see none of the differences could possibly cause any force-quitting issue… And I am pretty sure the project was working with the previous version of Xamarin…

Hi @KonajuGames, thanks for sharing your experience! So I guess my only option is to wait for a while until Xamarin 4 becomes stable enough? I don’t think downgrading to Xamarin 3 is a good idea… BTW I’m using the PC version of Xamarin Studio. :confused:

My lock file issue is the old project.json issue from the initial Windows 10 project types. Nothing to do with the Xamarin 4 upgrade. Damned red herrings.

Nope. Back to VS locking up while loading the solution.

Just checked out the Application Output and here is the error info regarding the release build force quitting:

[monodroid] Using override path: /data/data/com.greyp.mygame/files/.__override__
[monodroid] Trying to load sgen from: /data/data/com.greyp.mygame/files/.__override__/libmonosgen-2.0.so
[monodroid] Trying to load sgen from: /storage/emulated/0/Android/data/com.greyp.mygame/files/.__override__/libmonosgen-2.0.so
[monodroid] Trying to load sgen from: /data/app-lib/com.greyp.mygame-1/libmonosgen-2.0.so
[monodroid-gc] JNI weak global refs are broken on Android with the ART runtime.
[monodroid-gc] Trying to use java.lang.WeakReference instead, but this may fail as well.
[monodroid-gc] App stability may be compromised.
[monodroid-gc] See: https://code.google.com/p/android/issues/detail?id=63929
[monodroid-gc] GREF GC Threshold: 46080
[art] Thread[13,tid=8936,Native,Thread*=0x4cbbabf8,peer=0x64e4aea8,"Thread-1081"] attached without supplying a name
[art] JNI RegisterNativeMethods: attempt to register 0 native methods for opentk_1_0.GameViewBase
[Adreno-EGL] <qeglDrvAPI_eglInitialize:320>: EGL 1.4 QUALCOMM Build: I0404c4692afb8623f95c43aeb6d5e13ed4b30ddbDate: 11/06/13
[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] System.MissingMethodException: Constructor on type 'System.Runtime.Serialization.CollectionDataContract+GenericDictionaryEnumerator`2[[System.String, mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' not found.
[MonoDroid]   at System.RuntimeType.CreateInstanceImpl (BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes, System.Threading.StackCrawlMark& stackMark) <0x4da9ba50 + 0x00384> in <filename unknown>:0 
[art] JNI RegisterNativeMethods: attempt to register 0 native methods for md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable
[AndroidRuntime] Shutting down VM
[AndroidRuntime] FATAL EXCEPTION: main
[AndroidRuntime] Process: com.greyp.mygame, PID: 8869
[AndroidRuntime] java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
[AndroidRuntime] 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
[AndroidRuntime] Caused by: java.lang.reflect.InvocationTargetException
[AndroidRuntime] 	at java.lang.reflect.Method.invoke(Native Method)
[AndroidRuntime] 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
[AndroidRuntime] 	... 1 more
[AndroidRuntime] Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: System.MissingMethodException: Constructor on type 'System.Runtime.Serialization.CollectionDataContract+GenericDictionaryEnumerator`2[[System.String, mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' not found.
[AndroidRuntime]   at System.RuntimeType.CreateInstanceImpl (BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes, System.Threading.StackCrawlMark& stackMark) <0x4da9ba50 + 0x00384> in <filename unknown>:0 
[AndroidRuntime] 	at md5e322af307ce586010db6b75d08a37335.Activity1.n_onCreate(Native Method)
[AndroidRuntime] 	at md5e322af307ce586010db6b75d08a37335.Activity1.onCreate(Activity1.java:29)
[AndroidRuntime] 	at android.app.Activity.performCreate(Activity.java:5231)
[AndroidRuntime] 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
[AndroidRuntime] 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
[AndroidRuntime] 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
[AndroidRuntime] 	at android.app.ActivityThread.access$800(ActivityThread.java:135)
[AndroidRuntime] 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
[AndroidRuntime] 	at android.os.Handler.dispatchMessage(Handler.java:102)
[AndroidRuntime] 	at android.os.Looper.loop(Looper.java:136)
[AndroidRuntime] 	at android.app.ActivityThread.main(ActivityThread.java:5001)
[AndroidRuntime] 	... 3 more
[Process] Sending signal. PID: 8869 SIG: 9

So I guess this issue has something to do with the ART runtime?

Is it only me that is having this issue? Can someone help identify what the problem is? :frowning:

Are you using post build command line? I havent used the Android branch yet so i dont know if that is a default thing to do so, but it looks like a reference is just missing, (Which would normally throw errors you ccould solve from error report)

I have the same issue
Constructor on type ‘System.Runtime.Serialization.CollectionDataContract+GenericDictionaryEnumerator`2[[System.String, mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]’ not found.

I’d go through all the assemblies metadata and find out if any are referencing version 2.0.5.0 of mscorlib. If you find one then that is presumably the issue and needs updating.

@Damien_James_Gibson I’m not using post build command line :frowning:

No guarentee that this could be your problem but I had massive bugs using the target references… It would appear to target the right thing from the reference manager, but when i opened reference manager again it would show that the actual monogame that was being targeted was for windows phone which it pretty much jumps to as a default no matter which other version was selected… This threw all kinds of errors for me so you could see if the problem you are having is related >_>