Disappearing text (when using two different fonts)

I have a rather strange issue with some Labels. It currently only exists inside the GUI in my game, I have not yet tried to isolate it into a simple test case, so will explain the best I can.

I have…

Window 1

This has a custom SelectList type component, with each element in the list consisting of 3 different labels. 2 of these labels use the default font, the third uses a secondary font (actually a bold version of DejaVu Sans if it matters). On its own, this works fine.

Window 2

This has a load of DragElements (also custom), each of these has an icon and also is attached to a “tooltip” type component.
Again, the tooltip is not the standard tonegod one, as plain text did not suffice for my needs. So I created a Panel and extended Screen to manage it. One of the labels in this panel uses the same secondary font as is used in Window 1.

What happens …

When I hover over one of these icons in Window 2, the tooltip correctly appears. All the labels correctly display, and I see the text with this second font. However, any text that uses the same font in Window 1 has now disappeared!

Scrolling the list or doing anything that might causes Window 1 to redraw or adjust it’s layout or whatever, and the text reappears, in both places. I only see this behavior with this second font, which is defined in the style map.

Now I have got a lot custom components, and could easily be doing something crazy in one of them somewhere, so I may be on my own here :slight_smile: But, if anyone has any pointers as to what this may possibly be, it would be most appreciated.

ps: I’ll get a simple test application together when I have some time.

RR

1 Like

I’ve not had much time to do anything with this due to the holidays, but will be back to it after the 1st. Big family… a mom… etc, etc.

If you could throw together that small test app it would be a huge help!

Here is a test app, and thankfully the bug can reproduced easily using standard tooltips too. All you’ll need is an alternative font, just set the constant at the top of the class to it’s path.

If I happen to stumble across the cause between now and your return, I will of course post here.

Hope you and family have a great holiday :slight_smile:

[java]

import com.jme3.app.SimpleApplication;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector4f;
import com.jme3.renderer.RenderManager;
import tonegod.gui.controls.text.Label;
import tonegod.gui.controls.util.ToolTip;
import tonegod.gui.controls.windows.Window;
import tonegod.gui.core.Element;
import tonegod.gui.core.Screen;

public class TestWeirdness extends SimpleApplication {
//
// Set a font other than default, any one will do.
//
// VVVVVVVVVV CHANGE THIS VVVVVVVVVVV
public static final String INTERFACE_STYLES_GOLD_FONTS_ARCADEPIXFNT = “Interface/Styles/Gold/Fonts/Arcadepix.fnt”;
// ^^^^^^^^^^ CHANGE THIS ^^^^^^^^^^^

public static void main(String[] args) {
    TestWeirdness app = new TestWeirdness();
    app.start();
}

@Override
public void simpleInitApp() {
    flyCam.setDragToRotate(true);

    Screen screen = new Screen(this);
    screen.setUseToolTips(true);
    
    // Now we can get at tooltip and set the font. This is not exactly what I am
    // doing in my GUI, but thankfully the same bug occurs on standard tooltips using
    // this method
    ToolTip toolTip = (ToolTip)screen.getElementById("GlobalToolTip");
    toolTip.setFont(INTERFACE_STYLES_GOLD_FONTS_ARCADEPIXFNT);
    
    // Window 1        
    Window window1 = new Window(screen, new Vector2f(400, 300));
    window1.getDragBar().setText("Window 1");
    
    Label label1 = new Label(screen, new Vector2f(25, 70), new Vector2f(300, 24));
    label1.setFont(INTERFACE_STYLES_GOLD_FONTS_ARCADEPIXFNT);
    label1.setText("This text will start acting weird\nwhen tooltip is shown");
    window1.addChild(label1);
    
    // Window 2
    Window window2 = new Window(screen, new Vector2f(100, 100));
    window2.getDragBar().setText("Window 2");
    
    // Hover over the element to trigger the bug
    Element triggerBug = new Element(screen, "TriggerBug", new Vector2f(75, 90), new Vector2f(180, 20), Vector4f.ZERO, null);
    triggerBug.setText("Hover here to make text start disappearing!");       
    triggerBug.setToolTipText("Now the text in the other window will appear or disappear when you hover");
    
    // Add and show
    window2.addChild(triggerBug);
    screen.addElement(window1);
    screen.addElement(window2);
    guiNode.addControl(screen);

}

@Override
public void simpleUpdate(float tpf) {
}

@Override
public void simpleRender(RenderManager rm) {
}

}

[/java]

1 Like

I have narrowed down the cause of this a little. It appears to be something to do with Element.setFontPages(). Commenting out all of the code is this method fixes the problem, although no doubt it breaks other stuff horribly somewhere.

[java]
/**
* Updates font materials with any changes to clipping layers
*/
private void setFontPages() {
/if (textElement != null) {
if (!isVisible) {
for (int i = 0; i < font.getPageSize(); i++) {
this.font.getPage(i).setVector4(“Clipping”, clippingBounds);
this.font.getPage(i).setBoolean(“UseClipping”, true);
}
} else {
if (isClipped) {
for (int i = 0; i < font.getPageSize(); i++) {
this.font.getPage(i).setVector4(“Clipping”, clippingBounds.add(textClipPadding, textClipPadding, -textClipPadding, -textClipPadding));
this.font.getPage(i).setBoolean(“UseClipping”, true);
}
} else {
for (int i = 0; i < font.getPageSize(); i++) {
this.font.getPage(i).setBoolean(“UseClipping”, false);
}
}
}
}
/
}
[/java]

EDIT: I should have realised this, but commenting out the above messes up clipping of text. At least this shows the problem is somehow related.

EDIT: Completely ignore this post! I was being an idiot, this prevents the font change from happening at all. The only thing that fixes this issue is the commenting out of setFontPages() above.

I noticed this happening immediately (i.e. no hover involved) with some buttons where I used had used setFont() to set a custom font.

It looked like that setFont(String path) initializes the font differently to how it is done in the contructor, on a whim, I tried doing the same thing, and it seemed to do the trick. I am sort of curious why :slight_smile:

[java]
// Font & text
/**
* Sets the element’s text layer font
* @param fontPath String The font asset path
*/
public void setFont(String fontPath) {
// This doesn’t work. Fonts disappear
// font = app.getAssetManager().loadFont(fontPath);

            // This does   		    
        font.setCharSet(app.getAssetManager().loadFont(fontPath).getCharSet());
            
	if (textElement != null) {
		String text = this.getText();
		textElement.removeFromParent();
		textElement = null;
		setText(text);
	}
}

[/java]

RR

@rockfire said: EDIT: Completely ignore this post! I was being an idiot, this prevents the font change from happening at all. The only thing that fixes this issue is the commenting out of setFontPages() above.

I noticed this happening immediately (i.e. no hover involved) with some buttons where I used had used setFont() to set a custom font.

It looked like that setFont(String path) initializes the font differently to how it is done in the contructor, on a whim, I tried doing the same thing, and it seemed to do the trick. I am sort of curious why :slight_smile:

[java]
// Font & text
/**
* Sets the element’s text layer font
* @param fontPath String The font asset path
*/
public void setFont(String fontPath) {
// This doesn’t work. Fonts disappear
// font = app.getAssetManager().loadFont(fontPath);

            // This does   		    
        font.setCharSet(app.getAssetManager().loadFont(fontPath).getCharSet());
            
	if (textElement != null) {
		String text = this.getText();
		textElement.removeFromParent();
		textElement = null;
		setText(text);
	}
}

[/java]

RR

Hmmm… not sure why it would work this way and not the other. I’ll play around with trying to figure it out as well… if no solution can be found (i.e. removing the actual the cause), I see no issue with using what you are doing here, as it does the same thing (or has the same outcome).

Oh, I didn’t see this reply. See my above edit, this does not work at all, it just keeps the same font as was set originally.

I apologise if you wasted any time on this.

@rockfire said: Oh, I didn't see this reply. See my above edit, this does not work at all, it just keeps the same font as was set originally.

I apologise if you wasted any time on this.

Np at all. I think I know what the issue is anyways. I hope anyways. Will let you know if it is and what the issue was. If not… I’ll probably just cry a lot.

@t0neg0d said: Np at all. I think I know what the issue is anyways. I hope anyways. Will let you know if it is and what the issue was. If not.. I'll probably just cry a lot.

Lol. ok. Good luck. Would love to see this bug fixed! And I hope it doesn’t come to tears.

RR

I think this time I do have a working fix. I was on right track with Element.setFont(), but missed some bits :-

[java]
public void setFont(String fontPath) {

	// font = app.getAssetManager().loadFont(fontPath);
        
            // This was copied from constructor code that sets up font
            BitmapFont tempFont = app.getAssetManager().loadFont(fontPath);
	font = new BitmapFont();
	font.setCharSet(app.getAssetManager().loadFont(fontPath).getCharSet());
	Material[] pages = new Material[tempFont.getPageSize()];
	for (int i = 0; i &lt; pages.length; i++) {
		pages[i] = tempFont.getPage(i).clone();
	}
	font.setPages(pages);
            // -- end of new bit
        
	if (textElement != null) {
		String text = this.getText();
		textElement.removeFromParent();
		textElement = null;
		setText(text);
	}

}
[/java]

1 Like
@rockfire said: I think this time I do have a working fix. I was on right track with Element.setFont(), but missed some bits :-

[java]
public void setFont(String fontPath) {

	// font = app.getAssetManager().loadFont(fontPath);
        
            // This was copied from constructor code that sets up font
            BitmapFont tempFont = app.getAssetManager().loadFont(fontPath);
	font = new BitmapFont();
	font.setCharSet(app.getAssetManager().loadFont(fontPath).getCharSet());
	Material[] pages = new Material[tempFont.getPageSize()];
	for (int i = 0; i &lt; pages.length; i++) {
		pages[i] = tempFont.getPage(i).clone();
	}
	font.setPages(pages);
            // -- end of new bit
        
	if (textElement != null) {
		String text = this.getText();
		textElement.removeFromParent();
		textElement = null;
		setText(text);
	}

}
[/java]

Awesome! Thanks for this. This looks like how it is being set originally… not sure why I didn’t update it the same. >.<