HumbleUI / Skija

Java bindings for Skia
Apache License 2.0
514 stars 34 forks source link

skija.dll fails to load (windows 10 pro / directx12 ) #57

Open istinnstudio opened 1 year ago

istinnstudio commented 1 year ago

Hi.. coming back from an unsolved issue concerning incompatibility with systems that do not support dx12. https://github.com/HumbleUI/Skija/issues/38

Tested on 0.116.1 version. But surprisingly, trying to test some very simple skija examples in a different machine that supports dx12 (12gen intel, NVidia RTX GPU)) gives fatal error on loading skija.dll. I was wondering if we can spot the issue. I include a log. Tested on 3 different jvms, same results.

Tested on 0.116.1 version. image

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ff9a3b5cc00, pid=112124, tid=29404
#
# JRE version: OpenJDK Runtime Environment (17.0.7+7) (build 17.0.7+7-LTS)
# Java VM: OpenJDK 64-Bit Server VM (17.0.7+7-LTS, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, windows-amd64)
# Problematic frame:
# V  [jvm.dll+0x1cc00]
#
# 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:
# E:\...\hs_err_pid112124.log
#
# If you would like to submit a bug report, please visit:
#   https://bell-sw.com/support
#

hs_err_pid112124.log

tonsky commented 1 year ago

I’ll check on mine, see if it works

tonsky commented 1 year ago

Do Skija examples work for you by the way?

./examples/jwm/script/run.py --skija-version 0.116.1
istinnstudio commented 1 year ago

I will check that python script () but a t the moment I have just tried to use the library in windows 10 pro in netbeans. Release 0.116.1 jars windows x64 and shared. No errors from the IDE, the deprecated old methods I guess do not play any role.

import io.github.humbleui.skija.*;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ByteChannel;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class SkijaTestingWiki  extends JPanel {

        static {
    try {

   var path = System.getProperty("java.library.path");

   if (path == null) {
     throw new RuntimeException("Path isn't set.");
   }     

   System.out.println("Loading Library...");
//      System.loadLibrary("......../skija.dll");
//      System.load("........./skija.dll");
       System.out.println("Library Loaded.");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }
   public SkijaTestingWiki() {

      System.out.println("inside constructor 1");

   Surface surface = Surface.makeRasterN32Premul(100, 100);

   Paint paint = new Paint().setColor(0xFFFF0000);

Canvas canvas = surface.getCanvas().drawCircle(50, 50, 30, paint);

Image image = surface.makeImageSnapshot();
Data pngData = image.encodeToData(EncodedImageFormat.PNG);
ByteBuffer pngBytes = pngData.toByteBuffer();

try
{
    java.nio.file.Path path =  java.nio.file.Path.of("output.png");
    ByteChannel channel = Files.newByteChannel(
        path,
        StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE);
    channel.write(pngBytes);
    channel.close();
}
catch (IOException e)
{
    System.out.println(e);
}

   }

  public static void main(String[] args) {
    JFrame frame = new JFrame("Textures");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    SkijaTestingWiki sk1 =  new SkijaTestingWiki();
     frame.add(sk1);

//    frame.add(sk1);
    frame.setSize(360, 120);
    frame.setVisible(true);

  }

}
tonsky commented 1 year ago

You mean it worked?

istinnstudio commented 1 year ago

no I have just pasted a piece of code that produced the error. Any code that tried to load the dll gives the fatal error in my system. No errors by the IDE means that the library jars are in the classpath. Any obvious conclusion by reading the log?

tonsky commented 1 year ago

Well, works for me, but on Windows 11

istinnstudio commented 1 year ago

Its good to know that. For the time being there is nothing I can do. But If anyone with win10 could try it that would be a valuable information. It is strange, but an older, alternatively compiled version without directX12 dependency works ok, and because of the "old" jetbrains import both versions can be tested at the same time by just changing import statements. This one comes from a side project but obviously it has been compiled with opengl only params. I have just tested the above code simple example and it works. It is here (dll is in the releases): https://github.com/micycle1/processing-skia

Something in building process of the dll makes a dx12 dependency strictly for newer windows(?), but why not windows 10 that fully support dx12, I do not know.

If windows 10 is the case, there could be a way to expand compatibility in a next release

istinnstudio commented 1 year ago

Can someone expose the exact requirements for windows users and confirm that even OS can be an issue?? I had the sense that only dx12 GPU and drivers was the only requirement. DitectX11 capable GPUs cannot be used at any OS anyway (see https://github.com/HumbleUI/Skija/issues/38). But it seems it is deeper than this. An alternative dll build could be the solution and unfortunately I do not have the build environment needed to create a custom version of the dll.

istinnstudio commented 8 months ago

even the simplest example gives fatal error, there is no alternative, so the only way to be sure win10 directx is unsupported is someone with win10 can run skija without errors.

public class App {

    public static void main(String[] args) throws Exception {

        Surface surface = Surface.makeRasterN32Premul(100, 100);
        Canvas canvas = surface.getCanvas();

        Paint paint = new Paint();
        paint.setColor(0xFFAA0000);
        canvas.drawCircle(50, 50, 30, paint);

        Image image = surface.makeImageSnapshot();
        Data pngData = image.encodeToData(EncodedImageFormat.PNG);

        try (ByteChannel channel = Files.newByteChannel(
                java.nio.file.Path.of("build/output.png"),
                StandardOpenOption.CREATE,
                StandardOpenOption.TRUNCATE_EXISTING,
                StandardOpenOption.WRITE);
             surface) {
            channel.write(pngData.toByteBuffer());
        }
    }
}

# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ff8e5043a7e, pid=10360, tid=26548
#
# JRE version: OpenJDK Runtime Environment (21.0.2+14) (build 21.0.2+14-LTS)
# Java VM: OpenJDK 64-Bit Server VM (21.0.2+14-LTS, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, parallel gc, windows-amd64)
# Problematic frame:
# V  [jvm.dll+0x453a7e]
#
# 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:
tonsky commented 8 months ago

It’d be cool to have it working on Windows 10 or with DirectX 11 for sure, but I can’t do it myself unfortunately

istinnstudio commented 8 months ago

Maybe this issue resides on the python build scripts for win x64, could this have a simple solution on binary export configuration code? I do not know. If dx11 cannot be supported seems reasonable, but win10/dx12 is a "missing" feature request. Thanks tonsky for the replies, Lets see if one more person can actually test a win10/dx12 system and confirm this, if it actually works, then there could be a GPU drivers / jvm issue on my side, but I doubt this is the case.