Black textures on resume.

Hi there. I released my game on Google Play a couple of months back and it doesn’t have this problem, the app takes a few seconds to resume but the textures are all fine.

I have a copy of the Xamarin project folder for the version I released on Google Play but now when I build it, the textures created through Content.Load appear black when resuming. The only difference is that I have updated to the latest Xamarin studio and Xamarin.Android, I’ve tried rolling back to earlier versions but no luck.

I’ve read quite a few forum posts that mention GLSurfaceView.SetPreserveEGLContextOnPause for preventing loss of the GL context. None of them are really clear on how this should be implemented, ie. How do I get hold of a GLSurfaceView?

Any help would be appreciated.
Cheers,
Ronny.

Grab the latest version of monogame from git or from the buildbot.
We’ve had a few fixes related to resuming on android since the last stable release and we also do quick app resume now!

Thanks for the response. I’ve just built the very latest MonoGame.Framework.Android solution from GitHub and referenced the resulting MonoGame.Framework and Lidgren.Network dll’s in my own project. Everything compiles fine but when I run my app it hangs on startup with the following output:

[] Missing method Android.Media.AudioManager::GetProperty(string) in assembly Mono.Android.dll…

Opening the Mono.Android dll with the Assembly Browser shows that this method is actually there. I’m not sure what’s going on here?!?

Ronny.

You need to set your Android target version to level 17 or above I believe - I had this same issue.

Excellent, that’s my app working with the latest MonoGame code now. That fixes the texture problem and the quick resume works perfectly as a nice bonus. Thanks for the help guys.

1 Like

Hey, I am also having this problem where the screen appears black on resume. I see you said that it is fixed in the latest development build, however when I build this and add it to my references nothing changes and I get the same problem.

I am using Xamarin Studio running the Indie Edition. Any suggestions are much appreciated as this is the only thing keeping me from release.

I tested this on a Galaxy S3 and Moto G and it worked perfectly but the same build just displays a blank screen when I close and resume the app on a Nexus 7 tablet. The output window has the following error:

[libEGL] eglMakeCurrent:593 error 3009 (EGL_BAD_MATCH)

What device are you using benbillions? Sounds like you may be having a similar problem.

Thanks for the reply.

Emulator-wise, I have tested it on the default Mono-For_Android API 10 and 15 emulators in Xamarin Studio. I have also tested it on a HTC Inspire with Android 2.3.3. I noticed an error similar to the one you mentioned when resuming. Here is the output:

[EGL_emulation] [getAttribValue] Bad attribute idx
[EGL_emulation] tid 1239: eglGetConfigAttrib(606): error 0x3004 (EGL_BAD_ATTRIBUTE)
[MonoGame] AndroidGameWindow.SurfaceCreated: surfaceFrame = Rect(0, 0 - 240, 320)
[MonoGame] AndroidGameWindow.SurfaceChanged: format = Rgb565, width = 240, height = 320
[MonoGame] GraphicsDeviceManager.ResetClientBounds: newClientBounds={X:0 Y:0 Width:240 Height:320}
[EGL_emulation] eglSurfaceAttrib not implemented

Glad to hear, I am not the only one to have this issue.

Another similar problem from a few months back:

The fact that only a few people are noticing this suggests that it’s specific to certain Android versions. For me, it works fine on 4.1.2 (API 16) and 4.4.2 (API 19) but fails to resume on 4.2.1 (API 17).

I may just end up releasing anyway and it will hopefully be fixed in the next stable release of MonoGame, Android development is very very frustrating :frowning:

I would have expected this PR to have improved this on android, including the HTC One X

Hi there. I just downloaded the latest version from GitHub and the app now resumes correctly on the Nexus 7, good work on fixing that problem :smile:

I have however noticed an intermittent crash after maybe 2 or 3 resumes which happens across all of my devices, generating a load of NullReferenceExceptions, I’m guessing one per Texture:

[Error in swap buffers] System.NullReferenceException: Object reference not set to an instance of an object
[Error in swap buffers] at Microsoft.Xna.Framework.Graphics.RenderTarget2D.b__13 () [0x00000] in :0
[Error in swap buffers] at Microsoft.Xna.Framework.Graphics.GraphicsDevice.PlatformPresent () [0x00000] in :0
[Error in swap buffers] at Microsoft.Xna.Framework.Graphics.GraphicsDevice.Present () [0x00000] in :0
[Error in swap buffers] at Microsoft.Xna.Framework.AndroidGamePlatform.Present () [0x00000] in :0

Not a massive deal for me, just thought I’d let you know.

Thanks,
Ronny.

Actually, I’ve rolled back to the earlier version. My app has Facebook and Twitter integration and resuming from those intents is causing an intermittent hang on all devices. I’d rather my app worked perfectly on the majority of devices, it seems ok on an S3 and Moto G so I’m hoping it just affects a few devices. Hopefully the next official release of MonoGame will address this issue, it’s a bit of a showstopper.

I originated that other thread you linked to back there.

The pause/resume problems on HTC One X are definitely fixed. It’s rock solid now. I’m not using the very latest MG but one from a few weeks back - basically after the commit referenced above.

Just tried about ten successive pause/resumes on my game on the One X and all rock-solid.

I’m not using RenderTarget2Ds in this game mind you, I am using some textures created from streams though.

This whole issue is one that keeps cropping up and is a very important one for Android. Would be good if we had some kind of standard simple test app for the activity lifecycle stuff (and maybe a few other basics) and we could all contribute by testing on our various devices - results could be logged somewhere?

The simple test app is a good idea but I often find that these problems can be a combination of things and can’t always be reproduced in a simplified test environment.

I just re-tested the version of MonoGame I previously moaned about (from the PR that Dave mentioned) with a very simple project that just moves 20 copies of the same texture up and down the screen.

The resume works perfectly on all of my devices so it could be something to do with AdMob or my Twitter and Facebook intents, or something else?!? I’ll keep looking though, see if I can pinpoint the problem.