lwjglgamedev / lwjglbook-leg

Source code of the chapters of the book 3D Game Development with LWJGL 3

Home Page:https://ahbejarano.gitbook.io/lwjglgamedev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Java 9 compatibility

Baskiney opened this issue · comments

Hey,

it seems that the code is not working properly anymore with the new Java 9 version. They seem to have changed the behaviour of input-streams, so that compiling the input of the shader-files will throw an NPE under Java 9. Java 8 still works fine though.

Is there any chance of an update on this?

Sure! Can you point to the first chapter that you get the error?

The first occurrence of this would be in chapter 04. Although I personally tested it in chapter 06.

Thanks!

It's the way you load the shader code in from the file. Prior to Java 9 using Utils.class.getResourceAsStream() would have worked fine. Now with Java 9, you can't call getResourceAsStream from a static context.

Yes, the modules introduced in Java 9 have modified also teh way resources are loaded. I've just uploaded a version that supports Java 9. I will use that version as the default one, so I had also to move to IntelliJ since the other IDEs have some issues with Java 9.

Thanks por pointing the issue !

Hello,

first of all thanks for the quick responses but I still could not get it to compile on my System. Which is interesting, because it seems to have worked on yours when you updated it. I have found that modifying the InputStream to use the ContextClassLoader for the current Thread works for me personally.

If anyone is having issues like this after the update, he/she should try reading the Resources the following way:

    try (InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
         Scanner scanner = new Scanner(in, "UTF-8")) {
        result = scanner.useDelimiter("\\A").next();
    }

Any idea why this happens? Hope this helps!