I'm trying to load a TrueType font using libGDX's AssetManager class.
This is how I initialize my manager
variable:
manager = new AssetManager();
FileHandleResolver resolver = new InternalFileHandleResolver();
manager.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(resolver));
manager.setLoader(BitmapFont.class, ".ttf", new FreetypeFontLoader(resolver));
I've created a method, that searches for files in specified directory, and then using this code.. (it's in function, that takes path as argument)
FreeTypeFontLoaderParameter parameters = new FreeTypeFontLoaderParameter();
parameters.fontFileName = path;
parameters.fontParameters.size = 10;
manager.load(path, BitmapFont.class, parameters);
... adds font to load queue, but when I start my application, it keep throwing exception:
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.GdxRuntimeException: Asset not loaded: assets/fonts\Test.ttf.gen
at com.badlogic.gdx.assets.AssetManager.handleTaskError(AssetManager.java:536)
at com.badlogic.gdx.assets.AssetManager.update(AssetManager.java:356)
at my.app(App.java:56)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:215)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Asset not loaded: assets/fonts\Test.ttf.gen
at com.badlogic.gdx.assets.AssetManager.get(AssetManager.java:127)
at com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader.loadSync(FreetypeFontLoader.java:40)
at com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader.loadSync(FreetypeFontLoader.java:20)
at com.badlogic.gdx.assets.AssetLoadingTask.handleAsyncLoader(AssetLoadingTask.java:139)
at com.badlogic.gdx.assets.AssetLoadingTask.update(AssetLoadingTask.java:89)
at com.badlogic.gdx.assets.AssetManager.updateTask(AssetManager.java:477)
at com.badlogic.gdx.assets.AssetManager.update(AssetManager.java:354)
... 3 more
Line 56 at App.java looks like this:
if(!this.resourceManager.getManager().update()) {
I can read from exception that asset named 'Test.ttf.gen' could not be load, but I have no idea where I can get it... I mean, I have .ttf file, and I think that's enough.
I've searched Google, but it seems like no one had a similar problem.
I was having this issue only on Windows machines. Turns out that the class I was using to store asset paths returned strings with path separators specific to each platform. So on Windows it was returning a path string with forward slashes. Internally the LibGDX AssetManager class uses back slashes but would still load a string with forward slashes.
The problem is that the loaded asset was stored in a dictionary with the path as the string key with forward slashes. When you try to get the asset with the backslash path it can't find the key in the dictionary.
Long story short, make sure you check that your paths always use forward slashes with LibGDX even on Windows.
Also I might file a bug report.