Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Textures become black after returning #2244

Open
Felixxex opened this Issue Feb 23, 2014 · 3 comments

Comments

Projects
None yet
4 participants
@Felixxex
Copy link

Felixxex commented Feb 23, 2014

I'm developing a simple game for android at the moment.
When first starting the game, the colors are all fine and everything looks alright.
If I press the home button and then return to back to the game. All textures are black.

I'm drawing some text on the screen which is still blue when i come back.
So it's either a problem with my code, or something weird with Texture2D

this is how i load the font

font = Content.Load<SpriteFont>("spriteFont1");

this is how i load the texture:

        Texture2D sky = Globals.FilledRectangle(Color.Cyan, this.GraphicsDevice, new Vector2(SCREEN_WIDTH * scale.X, 100 * scale.Y));

        public static Texture2D FilledRectangle(Color color, GraphicsDevice gD, Vector2 size)
        {
            Color[] data = new Color[(int)size.X * (int)size.Y];
            Texture2D temp = new Texture2D(gD, (int)size.X, (int)size.Y);
            for (int count = 0; count < data.Length; count++)
            {
                data[count] = color;
            }
            temp.SetData(data);
            return temp;
        }
@KonajuGames

This comment has been minimized.

Copy link
Contributor

KonajuGames commented Feb 23, 2014

The OpenGL context is destroyed when the app is sent to the background, so
OpenGL resources such as textures must be recreated when the app is
resumed. Resources loaded by MonoGame are handled automatically, but since
you are creating and populating the textures yourself, it is your
responsibility to re-create those textures.​

@Felixxex

This comment has been minimized.

Copy link
Author

Felixxex commented Feb 24, 2014

What event am I looking at?
OnActivated?

@beeradmoore

This comment has been minimized.

Copy link

beeradmoore commented Apr 24, 2014

@KonajuGames , currently experiencing this on the 3.2 release even with

texture = Content.Load<Texture2D>("myTexturePath");

Had also modified ContentManager.cs like so

protected virtual void ReloadGraphicsAssets()
{
    foreach (var asset in LoadedAssets)
    {
        // This never executes as asset.Key is never null.  This just forces the 
        // linker to include the ReloadAsset function when AOT compiled.
        if (asset.Key == null)
            ReloadAsset(asset.Key, Convert.ChangeType(asset.Value, asset.Value.GetType()));

#if WINDOWS_STOREAPP
        var methodInfo = typeof(ContentManager).GetType().GetTypeInfo().GetDeclaredMethod("ReloadAsset");
#else
        var methodInfo = typeof(ContentManager).GetMethod("ReloadAsset", BindingFlags.NonPublic | BindingFlags.Instance);
#endif
        if (methodInfo != null)
        {
            var genericMethod = methodInfo.MakeGenericMethod(asset.Value.GetType());
            genericMethod.Invoke(this, new object[] { asset.Key, Convert.ChangeType(asset.Value, asset.Value.GetType()) }); 
        }
    }
}

to prevent linker stripping out certain functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.