jmecn / jme3-freetype-font

freetype font support for jme3
BSD 3-Clause "New" or "Revised" License
4 stars 0 forks source link

Problem with FtLibrary #5

Closed KiraLis39 closed 1 month ago

KiraLis39 commented 1 month ago

I try to use this library, but got an error: into constructor of class FtLibrary on line ok(FT_Init_FreeType(ptr))

10.10.24 08:58:16.992 [ERROR] th:jME3 Main c.j.a.LegacyApplication.handleError():683   Uncaught exception thrown in Thread[#71,jME3 Main,6,main]
java.lang.ExceptionInInitializerError: null
    at org.lwjgl.util.freetype.FreeType.nFT_Init_FreeType(FreeType.java:2916)
    at org.lwjgl.util.freetype.FreeType.FT_Init_FreeType(FreeType.java:2925)
    at io.github.jmecn.font.freetype.FtLibrary.<init>(FtLibrary.java:37)
    at io.github.jmecn.font.generator.FtFontGenerator.<init>(FtFontGenerator.java:97)
    at io.github.jmecn.font.generator.FtFontGenerator.<init>(FtFontGenerator.java:93)
    at io.github.jmecn.font.plugins.FtFontLoader.load(FtFontLoader.java:23)
    at com.jme3.asset.DesktopAssetManager.loadLocatedAsset(DesktopAssetManager.java:274)
    at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:390)
    at game.freya.gui.JMEApp.registerAppResources(JMEApp.java:151)
    at game.freya.gui.JMEApp.simpleInitApp(JMEApp.java:97)
    at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:240)
    at com.jme3.system.lwjgl.LwjglWindow.initInThread(LwjglWindow.java:608)
    at com.jme3.system.lwjgl.LwjglWindow.run(LwjglWindow.java:712)
    at java.base/java.lang.Thread.run(Thread.java:1570)
Caused by: java.lang.NullPointerException: A required function is missing: FT_Get_Default_Named_Instance
    at org.lwjgl.system.APIUtil.requiredFunctionMissing(APIUtil.java:145)
    at org.lwjgl.system.APIUtil.apiGetFunctionAddress(APIUtil.java:139)
    at org.lwjgl.util.freetype.FreeType$Functions.<clinit>(FreeType.java:183)
    ... 14 common frames omitted
Disconnected from the target VM, address: '127.0.0.1:5391', transport: 'socket'

Process finished with exit code 130

It happened when call: FtFontKey key = new FtFontKey("Interface/Fonts/Propaganda.ttf", 16, true);

in my method on app starts:

private void registerAppResources(AssetManager assetManager) {
        assetManager.registerLoader(FtFontLoader.class, "ttf");
        FtFontKey key = new FtFontKey("Interface/Fonts/Propaganda.ttf", 16, true);
        Constants.setFontPropaganda(assetManager.loadAsset(key));
...
KiraLis39 commented 1 month ago

Used: Java -> jdk 22.0.2

JME -> jme3-lwjgl3 3.7.0-beta1.2.2 (jme in Desktop app mode)

Freetype -> `

io.github.jmecn jme3-freetype-font 0.2.1
    <dependency>
        <groupId>org.lwjgl</groupId>
        <artifactId>lwjgl-freetype</artifactId>
        <version>3.3.4</version>
        <classifier>natives-windows</classifier>
        <scope>runtime</scope>
    </dependency>`
jmecn commented 1 month ago

A required function is missing: FT_Get_Default_Named_Instance

It seems the problem is version of lib freetype. This function is add in freetype 2.13.1, I don't know what version does lwjgl3.3.4 use.

Could you try to use a lower version of lwjgl3? like 3.3.2? I will check lwjgl3's dependency later.

jmecn commented 1 month ago

I can't reproduce the issue. I think the problem is freetype natives and library version not match.

try to add all these dependencies to your pom.xml

    <dependency>
      <groupId>org.lwjgl</groupId>
      <artifactId>lwjgl</artifactId>
      <version>3.3.4</version>
    </dependency>
    <dependency>
      <groupId>org.lwjgl</groupId>
      <artifactId>lwjgl-freetype</artifactId>
      <version>3.3.4</version>
    </dependency>
    <dependency>
      <groupId>org.lwjgl</groupId>
      <artifactId>lwjgl</artifactId>
      <classifier>natives-windows</classifier>
      <version>3.3.4</version>
    </dependency>
    <dependency>
      <groupId>org.lwjgl</groupId>
      <artifactId>lwjgl-freetype</artifactId>
      <classifier>natives-windows</classifier>
      <version>3.3.4</version>
    </dependency>
jmecn commented 1 month ago

and try this demo:

public class TestFtLibrary {
    public static void main(String[] args) {
        try (FtLibrary lib = new FtLibrary()) {
            System.out.println("freetype version:" + lib.getVersion());
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}
jmecn commented 1 month ago

and try this demo:

public class TestFtLibrary {
    public static void main(String[] args) {
        try (FtLibrary lib = new FtLibrary()) {
            System.out.println("freetype version:" + lib.getVersion());
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}
jmecn commented 1 month ago

A required function is missing: FT_Get_Default_Named_Instance

It seems the problem is version of lib freetype. This function is add in freetype 2.13.1, I don't know what version does lwjgl3.3.4 use.

Could you try to use a lower version of lwjgl3? like 3.3.2? I will check lwjgl3's dependency later.

lwjgl 3.3.2 use freetype version 2.13.0, and lwjgl 3.3.4 use freetype version 2.13.2. Which add new function FT_Get_Default_Named_Instance.

https://chromium.googlesource.com/chromium/src/third_party/freetype2/+/master/docs/CHANGES#59

jme3-freetype-font itself use lwjgl 3.3.2, if means 4 dependencies:

Your pom only changed one version of them. Add every denpendency to you pom or just keep them 3.3.2.

try to add all these dependencies to your pom.xml

    <dependency>
      <groupId>org.lwjgl</groupId>
      <artifactId>lwjgl</artifactId>
      <version>3.3.4</version>
    </dependency>
    <dependency>
      <groupId>org.lwjgl</groupId>
      <artifactId>lwjgl-freetype</artifactId>
      <version>3.3.4</version>
    </dependency>
    <dependency>
      <groupId>org.lwjgl</groupId>
      <artifactId>lwjgl</artifactId>
      <classifier>natives-windows</classifier>
      <version>3.3.4</version>
    </dependency>
    <dependency>
      <groupId>org.lwjgl</groupId>
      <artifactId>lwjgl-freetype</artifactId>
      <classifier>natives-windows</classifier>
      <version>3.3.4</version>
    </dependency>

To keep the version the same. I suggest use dependency managment.

  <properties>
    <lwjgl.version>3.3.2</lwjgl.version>
  </properties>

  <profiles>
    <profile>
      <id>lwjgl-natives-linux-amd64</id>
      <activation>
        <os>
          <family>unix</family>
          <name>linux</name>
          <arch>amd64</arch>
        </os>
      </activation>
      <properties>
        <lwjgl.natives>natives-linux</lwjgl.natives>
      </properties>
    </profile>
    <profile>
      <id>lwjgl-natives-macos-x86_64</id>
      <activation>
        <os>
          <family>mac</family>
          <arch>x86_64</arch>
        </os>
      </activation>
      <properties>
        <lwjgl.natives>natives-macos</lwjgl.natives>
      </properties>
    </profile>
    <profile>
      <id>lwjgl-natives-windows-amd64</id>
      <activation>
        <os>
          <family>windows</family>
          <arch>amd64</arch>
        </os>
      </activation>
      <properties>
        <lwjgl.natives>natives-windows</lwjgl.natives>
      </properties>
    </profile>
  </profiles>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.lwjgl</groupId>
        <artifactId>lwjgl-bom</artifactId>
        <version>${lwjgl.version}</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>
    </dependencies>
  </dependencyManagement>
KiraLis39 commented 1 month ago

A required function is missing: FT_Get_Default_Named_Instance

It seems the problem is version of lib freetype. This function is add in freetype 2.13.1, I don't know what version does lwjgl3.3.4 use.

Could you try to use a lower version of lwjgl3? like 3.3.2? I will check lwjgl3's dependency later.

Yes, I tried to run my app with version 3.3.2 etc. I alternated in different ways. There were other errors, but always an error.

KiraLis39 commented 1 month ago
<dependency>
      <groupId>org.lwjgl</groupId>
      <artifactId>lwjgl</artifactId>
      <version>3.3.4</version>
    </dependency>
    <dependency>
      <groupId>org.lwjgl</groupId>
      <artifactId>lwjgl-freetype</artifactId>
      <version>3.3.4</version>
    </dependency>
    <dependency>
      <groupId>org.lwjgl</groupId>
      <artifactId>lwjgl</artifactId>
      <classifier>natives-windows</classifier>
      <version>3.3.4</version>
    </dependency>
    <dependency>
      <groupId>org.lwjgl</groupId>
      <artifactId>lwjgl-freetype</artifactId>
      <classifier>natives-windows</classifier>
      <version>3.3.4</version>
    </dependency>

Yes, I see, Its work. All is good, Thanks a lot.

KiraLis39 commented 1 month ago

Everything is fine, but the application often starts with an error, immediately closes. Sometimes it starts normally, sometimes this error. In any case, I ask the authors to quickly update the library to more modern levels, it is very useful.

10.10.24 18:01:04.437 [INFO] th:jME3 Main i.g.j.f.f.FtLibrary.newFace():130   load input data:323768
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffa058cdd01, pid=4408, tid=11328
#
# JRE version: OpenJDK Runtime Environment (22.0.2+9) (build 22.0.2+9-70)
# Java VM: OpenJDK 64-Bit Server VM (22.0.2+9-70, mixed mode, emulated-client, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, windows-amd64)
# Problematic frame:
# C  0x00007ffa058cdd01
#
# No core dump will be written. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# H:\JavaProj\Games\FreyaTheGame\FreyaTheGame3D\hs_err_pid4408.log
[10.698s][warning][os] Loading hsdis library failed
#
# If you would like to submit a bug report, please visit:
#   https://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

Process finished with exit code -1073740791 (0xC0000409)

hs_err_pid4408.log

jmecn commented 1 month ago

jMonkeyEngine 3.7.0 itself depends on lwjgl 3.3.3, you'd better just keep the same version. Or there must be version conflicts.

jmecn commented 1 month ago

I'll release version 0.2.2 to maven center repository, update lwjgl3 version to 3.3.3.

KiraLis39 commented 1 month ago

Wow, this is cool. I love Swing, but JME+Swing is a bad idea. This library is a great option. It lacks many things, but I am adding them myself. Like Separator:

addChild(button);
addChild(new LSeparator(LSeparator.Type.HORIZONTAL, 6));
addChild(button2);
addChild(new LSeparator(LSeparator.Type.HORIZONTAL, 6));
addChild(button3);
public class LSeparator extends Container {

    public LSeparator() {
        this(Type.HORIZONTAL);
    }

    public LSeparator(Type type) {
        this(Type.HORIZONTAL, 3);
    }

    public LSeparator(Type type, float value) {
        switch (type) {
            case HORIZONTAL -> setInsets(new Insets3f(value, 0, value, 0));
            case VERTICAL -> setInsets(new Insets3f(0, value, 0, value));
        }
        setAlpha(0);
    }

    public enum Type {
        HORIZONTAL,
        VERTICAL
    }
}

It's just that Swing has new BodrerLayout(hgap: 6, vgap: 6), but here it doesn't yet.

KiraLis39 commented 1 month ago

By the way, I still haven't been able to set up a style for disabled buttons. Is there a way to display button.setEnabled(false) differently?