Crash when game launched in wrong orientation [SOLVED]

Hi guys, so I’ve ported my game to android and it all works fine except for one weird crash. The game is locked to landscape orientation but if I hold the device in portrait and launch the game it crashes immediately with the following error:

NoSuitableGraphicsDeviceException
MakeCurrent failed with error 12297

If I hold the device in landscape and launch the game it all works perfectly.

Anyone have any ideas?

this is the call stack:

System.Diagnostics.Debugger.Mono_UnhandledException_internal () in
System.Diagnostics.Debugger.Mono_UnhandledException (ex={Microsoft.Xna.Framework.Graphics.NoSuitableGraphicsDeviceException: MakeCurrent failed with error 12297 (0x3009) —> OpenTK.Platform.Android.EglException: MakeCurrent failed with error 12297 (0x3009)
at OpenTK.Platform.Android.AndroidGraphicsContext.MakeCurrent (IWindowInfo win) [0x000bc] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/OpenGLES/Android/AndroidGraphicsContext.cs:178
at OpenTK.Platform.Android.AndroidGameView.MakeCurrent () [0x0002b] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/OpenGLES/Android/AndroidGameView.cs:203
at Microsoft.Xna.Framework.MonoGameAndroidGameView.OnLoad (System.EventArgs eventArgs) [0x0000a] in /Users/Hammy/Projects/Drawtopia Android/References/MonoGame-develop/MonoGame.Framework/Android/MonoGameAndroidGameView.cs:123
— End of inner exception stack trace —
at Microsoft.Xna.Framework.MonoGameAndroidGameView.OnLoad (System.EventArgs) [0x0001e] in /Users/Hammy/Projects/Drawtopia Android/References/MonoGame-develop/MonoGame.Framework/Android/MonoGameAndroidGameView.cs:127
at OpenTK.Platform.Android.AndroidGameView.LoadInternal (System.EventArgs) [0x00003] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/OpenGLES/Android/AndroidGameView.cs:282
at OpenTK.Platform.Android.AndroidGameView.SurfaceCreated (Android.Views.ISurfaceHolder) [0x00052] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/OpenGLES/Android/AndroidGameView.cs:113
at Microsoft.Xna.Framework.MonoGameAndroidGameView.Android.Views.ISurfaceHolderCallback.SurfaceChanged (Android.Views.ISurfaceHolder,Android.Graphics.Format,int,int) [0x00087] in /Users/Hammy/Projects/Drawtopia Android/References/MonoGame-develop/MonoGame.Framework/Android/MonoGameAndroidGameView.cs:89
at Android.Views.ISurfaceHolderCallbackInvoker.n_SurfaceChanged_Landroid_view_SurfaceHolder_III (intptr,intptr,intptr,int,int,int) [0x00013] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Android.Views.ISurfaceHolder.cs:155
at (wrapper dynamic-method) object.2b10cd71-c106-4aa5-85ee-e797824f7467 (intptr,intptr,intptr,int,int,int) <IL 0x00029, 0x0007b>
}) in
object.2b10cd71-c106-4aa5-85ee-e797824f7467 (arg0=0x4020d1b0, arg1=0xa900019, arg2=0x5ce0001d, arg3=4, arg4=1280, arg5=800) in
Microsoft.Xna.Framework.MonoGameAndroidGameView.OnLoad (eventArgs=) in /Users/Hammy/Projects/Drawtopia Android/References/MonoGame-develop/MonoGame.Framework/Android/MonoGameAndroidGameView.cs:127
OpenTK.Platform.Android.AndroidGameView.LoadInternal (e={System.EventArgs}) in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/OpenGLES/Android/AndroidGameView.cs:282
OpenTK.Platform.Android.AndroidGameView.SurfaceCreated (holder={android.view.SurfaceView$4@41f808f0}) in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/OpenGLES/Android/AndroidGameView.cs:113
Microsoft.Xna.Framework.MonoGameAndroidGameView.Android.Views.ISurfaceHolderCallback.SurfaceChanged (holder={android.view.SurfaceView$4@41f808f0}, format=Android.Graphics.Format.Rgb565, width=1280, height=800) in /Users/Hammy/Projects/Drawtopia Android/References/MonoGame-develop/MonoGame.Framework/Android/MonoGameAndroidGameView.cs:89
Android.Views.ISurfaceHolderCallbackInvoker.n_SurfaceChanged_Landroid_view_SurfaceHolder_III (jnienv=0x4020d1b0, native__this=0xa900019, native_holder=0x5ce0001d, native_format=4, width=1280, height=800) in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Android.Views.ISurfaceHolder.cs:155
object.2b10cd71-c106-4aa5-85ee-e797824f7467 (arg0=0x4020d1b0, arg1=0xa900019, arg2=0x5ce0001d, arg3=4, arg4=1280, arg5=800) in

make sure you have set the allowed orientation in your Activity.cs (or equivalent)

[Activity(Label = "MyGame",
    ...    
    ScreenOrientation = ScreenOrientation.Landscape]

Are you also trying to set it in your manifest.xml file? Maybe there is a conflict

Thanks for the reply, yea I set this in my game.cs but even if I comment out the orientations the result is the same:

graphics.IsFullScreen = true;
graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;

My Activity.cs looks like this:

 namespace Drawtopia
    {
        // the ConfigurationChanges flags set here keep the EGL context
        // from being destroyed whenever the device is rotated or the
        // keyboard is shown (highly recommended for all GL apps)
        [Activity(Label = "Drawtopia",
    				#if __ANDROID_11__
    				HardwareAccelerated=false,
    				#endif
            ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.KeyboardHidden,
            MainLauncher = true)]
    
        public class MainActivity : AndroidGameActivity
        {
            protected override void OnCreate(Bundle bundle)
            {
                base.OnCreate(bundle);
    
                var game = new GameStateManagementGame();
    
                var frameLayout = new FrameLayout(this);
                frameLayout.AddView((View)game.Services.GetService(typeof(View)));
                this.SetContentView(frameLayout);
    
                //SetContentView(game.Window);
                game.Run(GameRunBehavior.Asynchronous);
            }
               
        }        
    }

Wait, think its fixed…

[Activity(Label = "MyGame",
    ...    
ScreenOrientation = ScreenOrientation.Landscape]

Added that to my activity.cs just like you said, commented out my old orientation code and its just launched 3 times in a row whilst holding it in portrait :smile:

Thanks man!!

Awesome, glad it worked!

For reference, if you end up building an iOS version, keep in mind you will have to set similar settings. You will have to need a declaration for graphics.SupportedOrientations in your game.cs file, as well as select the allowed orientations in your info.plist

Thanks, yea the iOS version is already released, it was much more obvious what to set with the info.plist.

Its my first time porting my XNA games so I’m learning these things as I go :slight_smile: