6
\$\begingroup\$

I am working on a libGDX project for Android. Since I added the following code, running the game on my Android phone produces an exception:

final FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fontFile);
final FreeTypeFontParameter parameter = new FreeTypeFontParameter();
parameter.size = 36;
this.font = generator.generateFont(parameter); // line 43
generator.dispose();

I am using libGDX version 1.7.0. Here is the gradle.build:

buildscript {
    repositories {
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        jcenter()
    }
    dependencies {
        classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
        classpath 'com.android.tools.build:gradle:1.2.3'
        classpath 'org.robovm:robovm-gradle-plugin:1.8.0'
    }
}

allprojects {
    apply plugin: "eclipse"
    apply plugin: "idea"

    version = '1.0'
    ext {
        appName = "unicorn"
        gdxVersion = '1.7.0'
        roboVMVersion = '1.8.0'
        box2DLightsVersion = '1.4'
        ashleyVersion = '1.6.0'
        aiVersion = '1.6.0'
    }

    repositories {
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "https://oss.sonatype.org/content/repositories/releases/" }
    }
}

project(":desktop") {
    apply plugin: "java"


    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
        compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
        compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
    }
}

project(":android") {
    apply plugin: "android"

    configurations { natives }

    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
        compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
    }
}

project(":core") {
    apply plugin: "java"


    dependencies {
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"

        compile 'org.apache.commons:commons-lang3:3.4'
        compile 'org.projectlombok:lombok:1.16.4'

    }
}

And the Exception:

F/art     (20518): art/runtime/check_jni.cc:64] JNI DETECTED ERROR IN APPLICATION: capacity must be greater than 0: 0
F/art     (20518): art/runtime/check_jni.cc:64]     in call to NewDirectByteBuffer
F/art     (20518): art/runtime/check_jni.cc:64]     from java.nio.ByteBuffer com.badlogic.gdx.graphics.g2d.Gdx2DPixmap.newPixmap(long[], int, int, int)
F/art     (20518): art/runtime/check_jni.cc:64] "GLThread 1777" prio=5 tid=14 Runnable
F/art     (20518): art/runtime/check_jni.cc:64]   | group="main" sCount=0 dsCount=0 obj=0x64d26b40 self=0x48e27b48
F/art     (20518): art/runtime/check_jni.cc:64]   | sysTid=20548 nice=0 cgrp=apps sched=0/0 handle=0x48e27e98
F/art     (20518): art/runtime/check_jni.cc:64]   | state=R schedstat=( 0 0 0 ) utm=7 stm=3 core=1 HZ=100
F/art     (20518): art/runtime/check_jni.cc:64]   | stack=0x48e41000-0x48e45000 stackSize=1040KB
F/art     (20518): art/runtime/check_jni.cc:64]   native: art::Thread::DumpStack(std::ostream&) const+87 [0x416f7cc8] (libart.so)
F/art     (20518): art/runtime/check_jni.cc:64]   native: ??? [0x415a49ae] (libart.so)
F/art     (20518): art/runtime/check_jni.cc:64]   native: art::JniAbortF(char const*, char const*, ...)+51 [0x415a5340] (libart.so)
F/art     (20518): art/runtime/check_jni.cc:64]   native: ??? [0x415b05f4] (libart.so)
F/art     (20518): art/runtime/check_jni.cc:64]   native: Java_com_badlogic_gdx_graphics_g2d_Gdx2DPixmap_newPixmap+92 [0x48def790] (libgdx.so)
F/art     (20518): art/runtime/check_jni.cc:64]   at com.badlogic.gdx.graphics.g2d.Gdx2DPixmap.newPixmap(Native method)
F/art     (20518): art/runtime/check_jni.cc:64]   at com.badlogic.gdx.graphics.g2d.Gdx2DPixmap.<init>(Gdx2DPixmap.java:94)
F/art     (20518): art/runtime/check_jni.cc:64]   at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:114)
F/art     (20518): art/runtime/check_jni.cc:64]   at com.badlogic.gdx.graphics.g2d.freetype.FreeType$Bitmap.getPixmap(FreeType.java:613)
F/art     (20518): art/runtime/check_jni.cc:64]   at com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.createGlyph(FreeTypeFontGenerator.java:475)
F/art     (20518): art/runtime/check_jni.cc:64]   at com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.generateData(FreeTypeFontGenerator.java:402)
F/art     (20518): art/runtime/check_jni.cc:64]   at com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.generateFont(FreeTypeFontGenerator.java:163)
F/art     (20518): art/runtime/check_jni.cc:64]   at com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.generateFont(FreeTypeFontGenerator.java:156)
F/art     (20518): art/runtime/check_jni.cc:64]   at org.tobinet.unicorn.Unicorn.create(Unicorn.java:43)
F/art     (20518): art/runtime/check_jni.cc:64]   at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:243)
F/art     (20518): art/runtime/check_jni.cc:64]   at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1514)
F/art     (20518): art/runtime/check_jni.cc:64]   at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1242)

What can I do to fix this?

\$\endgroup\$
0
\$\begingroup\$

Are you using the ART runtime in KitKat?

If this only happens when you run on run device, and not when run in desktop mode, and if you're using ART then I'd suggest trying to switch back to use DALVIK.

On your device;

  • Go into Settings/Developer options
  • Find Select runtime,
  • Tap DALVIK and then OK to reboot

Make sure you do this when the device is charging.

\$\endgroup\$
  • \$\begingroup\$ Thanks for the answer. After some reboots and rebuilds it was working again. Do not know what exactly fixed my issue! \$\endgroup\$ – Tobi Oct 18 '15 at 11:25
  • \$\begingroup\$ I changed fonts and it worked (same source works with Dalvik and not Art depending on the font...) github.com/libgdx/libgdx/issues/976#issuecomment-30218089 seems I was trying to get characters the font did not have... \$\endgroup\$ – CrandellWS Dec 17 '16 at 20:38
-3
\$\begingroup\$

Make sure that the font file string ends in .TFF not .tff

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.