JetBrains / skija

Java bindings for Skia
Apache License 2.0
2.63k stars 128 forks source link

LWJGL examples crash the JVM on Windows #84

Closed romanciloci closed 3 years ago

romanciloci commented 3 years ago

Hi, I was trying the lwjgl examples and my jvm was crashing when running the application on Windows 10 64bit The jvm crash log shows this:

... Host: Intel(R) Core(TM) i5-4460 CPU @ 3.20GHz, 4 cores, 31G, Windows 10 , 64 bit Build 18362 (10.0.18362.1110) Time: Wed Dec 30 15:36:18 2020 Eastern Standard Time elapsed time: 0.791668 seconds (0d 0h 0m 0s)

--------------- T H R E A D ---------------

Current thread (0x0000019f82f2f800): JavaThread "main" [_thread_in_native, id=7600, stack(0x0000008956200000,0x0000008956300000)]

Stack: [0x0000008956200000,0x0000008956300000], sp=0x00000089562ff180, free space=1020k Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) C [skija.dll+0x4629]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code) j org.jetbrains.skija.Font._nMakeTypefaceSize(JF)J+0 j org.jetbrains.skija.Font.(Lorg/jetbrains/skija/Typeface;F)V+6 j jskia.scene.TextLineScene.()V+158 j jskia.Window.loop()V+148 j jskia.Window.run(Lorg/jetbrains/skija/IRect;)V+14 j jskia.App.main([Ljava/lang/String;)V+95 v ~StubRoutines::call_stub

siginfo: EXCEPTION_ACCESS_VIOLATION (0xc0000005), writing address 0x0000000000000008

Register to memory mapping:

RIP=0x00007ffb84b44629 skija.dll RAX=0x0000000000000008 is an unknown value RBX={method} {0x0000019fb7b3c3b8} '_nMakeTypefaceSize' '(JF)J' in 'org/jetbrains/skija/Font' ...

The package names might be different than the ones from the skija examples folder but the code is exactly the same. If I comment out these lines in TextLineScene.java (and the code that depends on them):

private Font zapfino18 = new Font(FontMgr.getDefault().matchFamilyStyle("Zapfino", FontStyle.NORMAL), 18);
    private Font emoji36 = new Font(FontMgr.getDefault().matchFamilyStyle("Apple Color Emoji", FontStyle.NORMAL), 36);

then it works and the jvm doesn't crash

Are those fonts Apple specific ? Should the examples be run only on an Apple machine ?

I also tried to run the lwjgl examples on Linux (Ubuntu/Gnome 64bit) with maven and got the same result. The jvm crash log shows the same stack trace pointing to TextLineScene.java

This could probably be a new issue but I'll include it here. Once I comment the Apple fonts to get the application to start I get this NPE

Exception in thread "main" java.lang.NullPointerException: Cannot read field "_left" because "r" is null at org.jetbrains.skija.Canvas.drawRect(Canvas.java:229) at org.jetbrains.skija.examples.lwjgl.TextLineScene.drawLine(TextLineScene.java:72) at org.jetbrains.skija.examples.lwjgl.TextLineScene.draw(TextLineScene.java:123) at org.jetbrains.skija.examples.lwjgl.Window.draw(Main.java:145) at org.jetbrains.skija.examples.lwjgl.Window.loop(Main.java:368) at org.jetbrains.skija.examples.lwjgl.Window.run(Main.java:60) at org.jetbrains.skija.examples.lwjgl.Main.main(Main.java:31)

If I replace "" with " " on line 123 in TextLineScene.java then it works I guess it's something with getting the coord and/or lineHeight for an empty string.

tonsky commented 3 years ago

Yeah, those fonts are Apple specific. I’ll work around that, thank you!

tonsky commented 3 years ago

@romanciloci can you please check with current master and close if this is fixed? Thank you!

romanciloci commented 3 years ago

The lwjgl examples don't crash the jvm on Windows/Linux any more so the font loading change fixed it. Thanks for fixing this so quick!

However, I do get this exception now:

Exception in thread "main" java.lang.AssertionError: Can't drawRect with r == null at org.jetbrains.skija.Canvas.drawRect(Canvas.java:247) at org.jetbrains.skija.examples.lwjgl.TextLineScene.drawLine(TextLineScene.java:74) at org.jetbrains.skija.examples.lwjgl.TextLineScene.draw(TextLineScene.java:128) at org.jetbrains.skija.examples.lwjgl.Window.draw(Main.java:145) at org.jetbrains.skija.examples.lwjgl.Window.loop(Main.java:368) at org.jetbrains.skija.examples.lwjgl.Window.run(Main.java:60) at org.jetbrains.skija.examples.lwjgl.Main.main(Main.java:31)

which closes the window before any of the examples can be seen. It is caused by the "" at line 128 in TextLineScene.java

Should I create a separate issue for it and close this one ?

Thanks,

tonsky commented 3 years ago

Should I create a separate issue for it and close this one ?

I’ll take a look tomorrow, thanks