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

Font with shadows crashes #9

Closed
fgnm opened this issue May 17, 2020 · 11 comments
Closed

Font with shadows crashes #9

fgnm opened this issue May 17, 2020 · 11 comments
Assignees
Labels

Comments

@fgnm
Copy link

fgnm commented May 17, 2020

When I set shadow parameters in FreeTypeFontParameter the app crashes.

Here is a sample code:

    private void createFonts() {
        FreeTypeFontGenerator.setMaxTextureSize(1024);

        FreeTypeFontGenerator fontGenerator = mAssetManager.get(mTextFontDesc);
        FreeTypeFontGenerator.FreeTypeFontParameter fontParameter;
        BitmapFont font;

        fontParameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
        fontParameter.size = 64;
        //fontParameter.shadowColor = Color.BLACK;
        //fontParameter.shadowOffsetX = 6;
        //fontParameter.shadowOffsetY = 6;
        fontParameter.genMipMaps = true;
        fontParameter.minFilter = Texture.TextureFilter.MipMapLinearNearest;
        fontParameter.magFilter = Texture.TextureFilter.MipMapLinearNearest;

        font = fontGenerator.generateFont(fontParameter);
        font.setUseIntegerPositions(true);

        mMainTitleFontStyle = new Label.LabelStyle(font, new Color(0xf9f901ff));
    }

If I uncomment any of shadow parameter GWT application crashes with the following error:
Error: java.lang.RuntimeException: java.lang.ClassCastException.

I'm really confused about that.. what could be the cause?

@intrigus
Copy link
Owner

Please create a minimal runnable example.

@fgnm
Copy link
Author

fgnm commented May 17, 2020

Well, it is a very basic asset manager class:

public class Assets {
    private final AssetDescriptor<FreeTypeFontGenerator> mTextFontDesc = new AssetDescriptor<FreeTypeFontGenerator>("font/Mecha_Bold.ttf", FreeTypeFontGenerator.class);

    private AssetManager mAssetManager;
    public Label.LabelStyle mMainTitleFontStyle;

    public Assets() {
        mAssetManager = new AssetManager();
        mAssetManager.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(new InternalFileHandleResolver()));
        mAssetManager.setLoader(BitmapFont.class, ".ttf", new FreetypeFontLoader(new InternalFileHandleResolver()));
    }

    public void createAssets() {
        //Skip all other assets
        createFonts();
    }

    private void createFonts() {
        FreeTypeFontGenerator.setMaxTextureSize(1024);

        FreeTypeFontGenerator fontGenerator = mAssetManager.get(mTextFontDesc);
        FreeTypeFontGenerator.FreeTypeFontParameter fontParameter;
        BitmapFont font;

        fontParameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
        fontParameter.size = 64;
        //fontParameter.shadowColor = Color.BLACK;
        //fontParameter.shadowOffsetX = 6;
        //fontParameter.shadowOffsetY = 6;
        fontParameter.genMipMaps = true;
        fontParameter.minFilter = Texture.TextureFilter.MipMapLinearNearest;
        fontParameter.magFilter = Texture.TextureFilter.MipMapLinearNearest;

        font = fontGenerator.generateFont(fontParameter);
        font.setUseIntegerPositions(true);

        mMainTitleFontStyle = new Label.LabelStyle(font, new Color(0xf9f901ff));
    }

    public void dispose() {
        mAssetManager.dispose();
    }

    public boolean update() {
        return mAssetManager.update();
    }
}

Just create a new instance of Assets, call mAssets.load(), wait untile mAssets.update() becomes true and finally mAssets.createAssets();
On Android and iOS same code works fine.

@piotr-j
Copy link

piotr-j commented May 20, 2020

I can confirm that stuff explodes when shadow is set to something.

@intrigus
Copy link
Owner

That's great to know that stuff explodes when shadows are used.
I'll look into it some time.

@piotr-j
Copy link

piotr-j commented May 20, 2020

Not very useful, I'm aware. Sadly the exception seems to occur in the freetype.js code which makes it hard to debug.
https://gist.github.com/piotr-j/136324b790406cda7eb4b8a9a0d23692
From https://github.com/piotr-j/skin-composer/tree/gwt

@intrigus
Copy link
Owner

@piotr-j do you by chance have a runnable and web accessible gwt version?
Or could you provide a more debug friendly stacktrace?
(I currently haven't setup libgdx or gwt^^)

@piotr-j
Copy link

piotr-j commented May 21, 2020

Ill make one today. Is there more readable freetype.js somewhere?

@piotr-j
Copy link

piotr-j commented May 21, 2020

Runnable http://piotrjastrzebski.io/gwt-freetype-test/
Source https://github.com/piotr-j/gwt-freetype-test
Let me know if there is anything else I can do to make this easier

@intrigus
Copy link
Owner

Please try the new version "1.9.10.1" when it has reached maven central.
That may take up to one day.

Using your test it works.
@fgnm please confirm that it also works for you.

@piotr-j
Copy link

piotr-j commented May 22, 2020

1.9.10.1 works, fantastic! How did you figure it out? Seems the cast was one of the issues, but i didnt get reasonable stacktraces for this...

@intrigus
Copy link
Owner

I told eclipse to compile gwt using -style PRETTY.
That produced readable enough stacktraces.
As soon as I saw the code the problem was clear :)

Closing as fixed.

@intrigus intrigus added the bug label May 23, 2020
@intrigus intrigus self-assigned this May 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants