[Archive] MonoGame iOS UI freeze

Posted by : at

Category : archive


Appearently, MonoGame 3.8.0.1641 has a bug in the Texture2D.GetData() call on iOS: if you call this method from either Update or Draw methods, the UI thread on the phone freeze (although the game will be running in the background). The solution is simple (at least it was for me): move all your GetData calls out of the Draw and Update methods to the game’s initialization part. Chances are you are using GetData to alter a texture. If this is the case, you can probably replace all your GetData calls with using RenderTarget2D which is not using GetData at all. If you are using GetData to analyse a texture, you can probably just move it to LoadContent() method at the beginning. And there is a second reason why should get rid of your GetData calls.

This part is appicable for everyone, not just for those who are targeting iOS: GetData alwyas reads the whole texture as of MonoGame 3.8.0.1641, which has a huge impact on your game’s performance. So even if you are you unaffected by the iOS bug, its a good idea to do all these calls during initialization, otherwise it can (and in case of bigger textures, it will) decrease your game’s performance, which is very precious, especially on mobile platforms.


About Lajos
Lajos

Enterprise Java for a living. Video game development for the soul.

Email : lajbertgames@gmail.com

Website : https://lajbert.github.io

About Lajbert

My name is Lajos, a software engineer who decided to chase his childhood dream of becoming a video game developer. I have a long road ahead of me until I can release my first game, but the path taking me there is already very rewarding. There are many great people around the internet who spends time, energy and even money to make great tutorials, shares their Github repos and distribute knowledge, and this blog is my attempt to pay my respect to them and follow their lead of giving back to the community. You’ll find tips, tricks, bits and pieces of what I learned while working on my project, which is also my learning path, so if you see something on my blog that is incorrect or can be done better, please leave a comment, so we all can learn something. Considering the risks I see using MonoGame at its current state, I've decided to (at least temporarly) retire my own game engine called Monolith Engine, and migrate my game onto Godot engine. Still, the code for Monolith Engine will stay available, many of my ideas are generic, and can easily be translated to your favorite language or game engine.

Star
Categories
Useful Links