androidlibgdxbitmap-fonts

android libgdx bitmap fonts turn to black rectangles after a while


I'm using gdx-freetype library in android to generate BitmapFont from TrueType font which is in assets/fonts/arial.ttf This is the way I use to show some text on screen

generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/arial.ttf"));
font30 = generator.generateFont(60 , "ConectigTsrv" , false);
generator.dispose();    
Label l = new Label("Connecting to server...", new LabelStyle(font30 , Color.BLUE));
l.setX(400 - l.getWidth()/2f);
l.setY(480 - l.getHeight() - 10);
stage.addActor(l);

text will be printed to screen very well

enter image description here

But after a while or when I push Home button and then come back to application all characters turn to black rectangles

enter image description here

Any idea about whats going on?


Solution

  • The problem is that the textures created by FreeTypeFontGenerator were not managed until this recent commit. The fact that textures are unmanaged means that they have to be reloaded following a loss of the OpenGL context, which occurs in scenarios such as the one you described.

    If you upgrade libgdx to the latest nightlies then the problem will probably go away.

    For more information, the problem with unmanaged textures is described very well in this article.