Monogame: System.InvalidOperationException: Framebuffer was not created correctly: FramebufferIncompleteAttachment

Created on 17 Apr 2020  路  10Comments  路  Source: MonoGame/MonoGame

My game currently has about 2.5K daily active iOS users who generate about 300 crashes per day with the following call stack:

System.InvalidOperationException: Framebuffer was not created correctly: FramebufferIncompleteAttachment
at Microsoft.Xna.Framework.iOSGameView.CreateFramebuffer ()
at Microsoft.Xna.Framework.iOSGameView.LayoutSubviews ()
at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate)
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName)

I've added tracing which shows the crash happens immediately after Microsoft.Xna.Framework.Game.OnDeactivated is invoked. Prior to that, the game has been running fine for a long time (30 minutes or more in some cases I inspected), and OnDeactivated may have been successfully invoked a number of times before the one that finally crashes, so the issue is intermittent and I suspect some sort of timing issue.

My best guess is that some GL drawing functions are being called after the game is deactivated, but I don't know how I can work around this issue. As you might imagine, this is not creating a good experience for my players.

Any advice?

What version of MonoGame does the bug occur on:

  • MonoGame 3.8

What operating system are you using:

  • Windows

What MonoGame platform are you using:

  • iOS
Help Wanted OpenGL iOS

All 10 comments

Which MonoGame 3.8 are you using? Last installer build from the build bot?

Exception is thrown here:
https://github.com/MonoGame/MonoGame/blob/a50501f5facdbb4e7fdc3d5c22677b8f83d90dc6/MonoGame.Framework/Platform/iOS/iOSGameView.cs#L256-L259

GL docs: https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glCheckFramebufferStatus.xhtml

GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT is returned if any of the framebuffer attachment points are framebuffer incomplete.

Which MonoGame 3.8 are you using? Last installer build from the build bot?

This has been a long-standing issue with many different daily builds of 3.8, and I believe even going back to 3.7. It's just become a higher priority now that one of my games is getting popular.

Unfortunately, I'm unable to use very recent builds of 3.8 due to breaking changes in the content pipeline. I have a dependency on a custom pipeline extension that doesn't load anymore and it's going to take some time to get it working again as I don't have the source and need to recreate it from scratch.

So, I'm synced to commit d04630b672c14379bf849baec0b7a76cbc8eb714 which contains the last fix that I require for issue #7047.

due to breaking changes in the content pipeline.

What breaking changes?

So, I'm synced to commit d04630b which contains the last fix that I require for issue #7047.

You don't have #7073 I assume.

I don't want to mix up too many issues here, but I also get hundreds of crashes per day that look like the following:

Foundation.MonoTouchException: Objective-C exception thrown.  Name: NSInternalInconsistencyException Reason: Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.
Native stack trace:
0   CoreFoundation                      0x000000018e1c8980 DC2C95C6-B954-39E8-86A2-5E0AF8801E87 + 1255808
1   libobjc.A.dylib                     0x000000018dee1028 objc_exception_throw + 60
2   Foundation                          0x000000018e6b45e0 7A7A96AF-79E4-3DB1-8904-42E61CAE8999 + 2332128
3   Foundation                          0x000000018e4ad854 7A7A96AF-79E4-3DB1-8904-42E61CAE8999 + 206932
4   Foundation                          0x000000018e4ad768 7A7A96AF-79E4-3DB1-8904-42E61CAE8999 + 206696
5   Foundation                          0x000000018e4ad3d8 7A7A96AF-79E4-3DB1-8904-42E61CAE8999 + 205784
6   UIKitCore                           0x00000001927695b8 AAFEFEBE-C172-3346-8972-810EB8F2F2C6 + 15611320
7   UIKitCore                           0x000000019277c8b0 AAFEFEBE-C172-3346-8972-810EB8F2F2C6 + 15689904
8   libobjc.A.dylib                     0x000000018dedca4c 2C18C54E-6C84-310C-851F-F9602890D908 + 6732
9   QuartzCore                          0x0000000194d9255c 4DA865CA-7F36-3D7F-952E-05A9E5ED505D + 1402204
10  QuartzCore                          0x0000000194d929ac 4DA865CA-7F36-3D7F-952E-05A9E5ED505D + 1403308
11  QuartzCore                          0x0000000194da51bc 4DA865CA-7F36-3D7F-952E-05A9E5ED505D + 1479100
12  QuartzCore                          0x0000000194ce9b00 4DA865CA-7F36-3D7F-952E-05A9E5ED505D + 711424
13  QuartzCore                          0x0000000194d14910 4DA865CA-7F36-3D7F-952E-05A9E5ED505D + 887056
14  QuartzCore                          0x0000000194d154e4 4DA865CA-7F36-3D7F-952E-05A9E5ED505D + 890084
15  CoreFoundation                      0x000000018e143524 DC2C95C6-B954-39E8-86A2-5E0AF8801E87 + 709924
16  CoreFoundation                      0x000000018e13e1c4 DC2C95C6-B954-39E8-86A2-5E0AF8801E87 + 688580
17  CoreFoundation                      0x000000018e13df60 CFRunLoopRunSpecific + 512
18  WebCore                             0x0000000196318820 CA426A2F-5481-34AC-AF0A-08332C0A84E0 + 4438048
19  libsystem_pthread.dylib             0x000000018ded1840 _pthread_start + 168
20  libsystem_pthread.dylib             0x000000018ded99f4 thread_start + 8
0   CoreFoundation                      0x000000018e1c8980 DC2C95C6-B954-39E8-86A2-5E0AF8801E87 + 1255808
1   libobjc.A.dylib                     0x000000018dee1028 objc_exception_throw + 60
2   Foundation                          0x000000018e6b45e0 7A7A96AF-79E4-3DB1-8904-42E61CAE8999 + 2332128
3   Foundation                          0x000000018e4ad854 7A7A96AF-79E4-3DB1-8904-42E61CAE8999 + 206932
4   Foundation                          0x000000018e4ad768 7A7A96AF-79E4-3DB1-8904-42E61CAE8999 + 206696
5   Foundation                          0x000000018e4ad3d8 7A7A96AF-79E4-3DB1-8904-42E61CAE8999 + 205784
6   UIKitCore                           0x00000001927695b8 AAFEFEBE-C172-3346-8972-810EB8F2F2C6 + 15611320
7   UIKitCore                           0x000000019277c8b0 AAFEFEBE-C172-3346-8972-810EB8F2F2C6 + 15689904
8   libobjc.A.dylib                     0x000000018dedca4c 2C18C54E-6C84-310C-851F-F9602890D908 + 6732
9   QuartzCore                          0x0000000194d9255c 4DA865CA-7F36-3D7F-952E-05A9E5ED505D + 1402204
10  QuartzCore                          0x0000000194d929ac 4DA865CA-7F36-3D7F-952E-05A9E5ED505D + 1403308
11  QuartzCore                          0x0000000194da51bc 4DA865CA-7F36-3D7F-952E-05A9E5ED505D + 1479100
12  QuartzCore                          0x0000000194ce9b00 4DA865CA-7F36-3D7F-952E-05A9E5ED505D + 711424
13  QuartzCore                          0x0000000194d14910 4DA865CA-7F36-3D7F-952E-05A9E5ED505D + 887056
14  QuartzCore                          0x0000000194d154e4 4DA865CA-7F36-3D7F-952E-05A9E5ED505D + 890084
15  CoreFoundation                      0x000000018e143524 DC2C95C6-B954-39E8-86A2-5E0AF8801E87 + 709924
16  CoreFoundation                      0x000000018e13e1c4 DC2C95C6-B954-39E8-86A2-5E0AF8801E87 + 688580
17  CoreFoundation                      0x000000018e13df60 CFRunLoopRunSpecific + 512
18  WebCore                             0x0000000196318820 CA426A2F-5481-34AC-AF0A-08332C0A84E0 + 4438048
19  libsystem_pthread.dylib             0x000000018ded1840 _pthread_start + 168
20  libsystem_pthread.dylib             0x000000018ded99f4 thread_start + 8

In this case, Microsoft.Xna.Framework.Game.Initialize gets called again after the game has been running for a long time, but has just been reactivated.

I do suspect some sort of multithreading issue here and maybe it's related?

You don't have #7073 I assume.

No, and that looks very promising. I'll see if I can get that change without the breaking content pipeline changes.

I was able to pick up #7073 so I'll put that in the App Store and close this issue for now. Thank you!

What breaking changes?

Effects compiled with the old content pipeline can't be loaded by current builds (throws an exception about the effect being an old version), and the new content pipeline builder fails to load old extensions so I can't rebuild the effects.

Now that I think about it, since I don't need the extension to build the effects (the extension is just supporting a replacement for SpriteFont that uses msdf font smoothing), maybe I could build everything else with the new content pipeline and keep just the old font xnb to work around this issue? I may try that later to see if I can get to a current build that way.

This is still an issue with #7073. It did seem to fix a bunch of other random crashes that were happening less often, but this one is still my top crash report.

More info:

In my latest release, 100% of the crashes so far happen after Game.OnDeactivated is called.

I also see an orientation change at some point before the crash.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bjornenalfa picture bjornenalfa  路  5Comments

tomspilman picture tomspilman  路  4Comments

monsieurmax picture monsieurmax  路  5Comments

SenpaiSharp picture SenpaiSharp  路  3Comments

rds1983 picture rds1983  路  5Comments