getAWTgraphicsconfiguration() causes NPE error

classic Classic list List threaded Threaded
19 messages Options
Reply | Threaded
Open this post in threaded view
|

getAWTgraphicsconfiguration() causes NPE error

Mr. Broccoli
Hi,

I was advised to search help on below on this forum.
Would anybody be able to help me with the question I placed on StackOverflow?

https://stackoverflow.com/questions/69775554/getawtgraphicsconfiguration-returns-null-error

Kind regards, Mr. B
Reply | Threaded
Open this post in threaded view
|

Re: getAWTgraphicsconfiguration() causes NPE error

philjord
Hi,
Thanks for posting the question.

This is a config issue, which I'll see if I can give you some debug code for to find out what's happening.

In the mean time your code works fine, I've cut and paste and it runs "out of the box" for me.

You can do it in a single java file just put the main method at the bottom of tuval7 class.

Also you'll want to add the noerasebackground property to stop awt from blocking the 3d view like so:

public static void main(String[] args) {
    System.setProperty("sun.awt.noerasebackground", "true");
        new tuval7();
    }



Your bug is happening here (as you've provided)
https://github.com/hharrison/java3d-core/blob/master/src/javax/media/j3d/JoglPipeline.java#L8291
so the cause is a null coming from the config table above, either
GraphicsConfiguration gconfig is no good,
or
Canvas3D.graphicsConfigTable has nothing compatible in it


Given that you have the jogamp-fat.jar file, can you run it with java and paste the output in a reply below

So just run a command like this in the folder that jogamp-fat is in
java -jar jogamp-fat2.4.0.jar 2> output.txt

It should spew out a bunch of config settings available on your machine (or perhaps an error)

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: getAWTgraphicsconfiguration() causes NPE error

Mr. Broccoli
Hi Phil,

Thanks for caring! : )

Not sure if it matters, but my jogamp-fat.jar file has a bit different name ('out of a 7z') than in your command.
When I run slightly altered command it revealed version 2.4 so I suppose it's irrelevant, true?

Here's the config, no error.

output.txt

Thanks

Reply | Threaded
Open this post in threaded view
|

Re: getAWTgraphicsconfiguration() causes NPE error

philjord
That's great, your environment is almost the same as mine.

The next step is probably to investigate Julien's suggestion on stackoverflow of checking for unexpected jar files in the load

It's not easy to get a jar listing out of Java, it depends a bit on your IDE.
I'm using Eclipse and the run configurations dialog has a "Show Command Line"

Which gives me
C:\Program Files\Java\jdk1.8.0_25\bin\javaw.exe
-Dfile.encoding=Cp1252
-classpath "E:\Java3D\workspace-1.6\test\bin;C:\Users\pjnz\.m2\repository\org\jogamp\jogl\jogl-all\2.3.2\jogl-all-2.3.2.jar;C:\Users\pjnz\.m2\repository\org\jogamp\gluegen\gluegen-rt\2.3.2\gluegen-rt-2.3.2.jar;C:\Users\pjnz\git\java3d-utils-1.6.0\bin;C:\Users\pjnz\git\java3d-core-1.6.0\bin;C:\Users\pjnz\git\vecmath-1.6.0\bin;E:\Java3D\workspace-1.6\java3d-examples\bin" _testcase.tuval7

so I notice I'm using the maven 2.3.2 version of jogl (just randomly I guess)

If the above doesn't give a clue about other jars on the classpath you could try witht eh 2.3.2 fat jar instead here:
https://jogamp.org/deployment/jogamp-current/archive/jogamp-fat-all.7z
Reply | Threaded
Open this post in threaded view
|

Re: getAWTgraphicsconfiguration() causes NPE error

Mr. Broccoli
Hi Phil,

I couldn't find a command to list attached jars in Netbeans, but when checking project properties, classpath is listed there. I took a snippet - see attached:
libs.PNG
Is this enough to convince you no obsolete versions are taken into account on run time?

When I swap 'fat' jar with the one you gave me a link to, the error in Netbeans changes to:
new_errors.txt
Maybe this could give you a clue you need to solve this puzzle?

Since I have Eclipse already installed, I just created a new project there and the code runs, but spews a few warnings:
eclipse_warning.PNG
Are these warnings serious (I don't know what reflective access is yet)?
If it's easier to configure it properly in Eclipse and get rid of these warnings, I can switch IDEs to make it work.

Kind regards, Mr. B.


Reply | Threaded
Open this post in threaded view
|

Re: getAWTgraphicsconfiguration() causes NPE error

philjord
Mr. B.

The Illegal reflexive access isn't currently a problem, I just it was added originally to Java3D to allow new Pipelines (like JoglPipeline) to be loaded at runtime, like code injection on application servers, and it's 100% useless now, so in a future build I'll just swap it for a simple switch case.

If it's running in Eclipse then I'm still pondering unusual jar loading (sorry to harp on).

Sometimes the extension directory can be trouble could you swap your main call to this and see what it produces?

public static void main(String[] args) {
   
    String extdir = System.getProperty("java.ext.dirs");
    System.out.println(extdir);
    String[] extdirs = extdir.split(";");
    for(String eds : extdirs) {
            File ed = new File(eds);
            System.out.println("ed "+ed);
            System.out.println(""+ed.exists());
            if(ed.exists()) {
            for(File f : ed.listFiles()) {
            System.out.println(" f: "+ f.getName());
            }    
            }    
    }
   
   
    System.setProperty("sun.awt.noerasebackground", "true");
        new tuval7();
    }



For me I get:

C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext;C:\WINDOWS\Sun\Java\lib\ext
ed C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext
true
 f: access-bridge-64.jar
 f: cldrdata.jar
 f: dnsns.jar
 f: jaccess.jar
 f: jfxrt.jar
 f: localedata.jar
 f: meta-index
 f: nashorn.jar
 f: sunec.jar
 f: sunjce_provider.jar
 f: sunmscapi.jar
 f: sunpkcs11.jar
 f: zipfs.jar
ed C:\WINDOWS\Sun\Java\lib\ext
false

Thanks,
Phil.
Reply | Threaded
Open this post in threaded view
|

Re: getAWTgraphicsconfiguration() causes NPE error

Mr. Broccoli
Phil,

It produces:

null
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.split(String)" because "extdir" is null
        at tuval1.main(tuval1.java:12)
C:\Users\PC\AppData\Local\NetBeans\Cache\12.4\executor-snippets\run.xml:111: The following error occurred while executing this line:
C:\Users\PC\AppData\Local\NetBeans\Cache\12.4\executor-snippets\run.xml:68: Java returned: 1
BUILD FAILED (total time: 0 seconds)

Regards, Mr. B.
Reply | Threaded
Open this post in threaded view
|

Re: getAWTgraphicsconfiguration() causes NPE error

gouessej
Administrator
There is no extension mechanism in your version of Java, it was removed in Java 9 (no extdir property as a consequence). Check that you didn't put JARs into your JRE too.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: getAWTgraphicsconfiguration() causes NPE error

Mr. Broccoli
Had some exams recently, hence the pause in replying.
I found some duplicates (old 2007 version), but after renaming these files/folders error still persists.
To be frank, I prefer moving on with Eclipse, unless you want to dig deeper.

Thanks for your efforts so far.
Maybe the error message did not get resolved, but I have progressed (using Eclipse) with what I'm trying to do thanks to your involvement .

Kind regards, Mr. B.
Reply | Threaded
Open this post in threaded view
|

Re: getAWTgraphicsconfiguration() causes NPE error

Oskarnaugh
Hi!
As I was updating our project's JDK version from version 1.8 to a newer one, I came across this very same issue. It happens with java versions 16 and on and I get the following error message:
Cannot invoke "com.jogamp.nativewindow.awt.AWTGraphicsConfiguration.getAWTGraphicsConfiguration()" because "<local3>" is null

With versions 11 to 15 the code runs correctly although showing the following warning message:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by javax.media.j3d.JoglPipeline (file:/.../Java3D/1.6.2/j3dcore.jar) to method sun.awt.AppContext.getAppContext()


I am using Java3D version 1.6.2 and jogamp-fat.jar version 2.4.0-rc-20210111
I have tried with several JDK distributors (OpenJDK, Zulu, etc.) as well as with Java3D versions 1.7.0 and 1.7.1-build-20200222, unfortunately resulting always in the same error.

To reproduce it one just have to try to create a Canvas3D:
new Canvas3D(SimpleUniverse.getPreferredConfiguration());

Using a GraphicsConfigTemplate3D results in the same error:
final GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D();
final GraphicsConfiguration graphicsConfiguration = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getBestConfiguration(template);
new Canvas3D(graphicsConfiguration);


I hope you can help me with this issue, so that I can update our project's JDK.
Thanks in advance.
Reply | Threaded
Open this post in threaded view
|

Re: getAWTgraphicsconfiguration() causes NPE error

gouessej
Administrator
Reply | Threaded
Open this post in threaded view
|

Re: getAWTgraphicsconfiguration() causes NPE error

Oskarnaugh
Thanks for the quick reply!

I added the option --add-opens=java.desktop/sun.awt=ALL-UNNAMED to the VM arguments but the results were the same in both Java3D versions (1.6.2 and 1.7.1)
Also without the option it still runs on Java versions 11 to 14. The warning message is still the same with or without said option for those versions
Reply | Threaded
Open this post in threaded view
|

Re: getAWTgraphicsconfiguration() causes NPE error

gouessej
Administrator
I think that the code emitting some warnings should be removed anyway, it was there to work around a bug in Java Webstart which was removed a while ago from Java. "<local3>" is null is the expected behaviour as there is no extension mechanism.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: getAWTgraphicsconfiguration() causes NPE error

Oskarnaugh
I found out the source of the warnings:
They appear as soon as I use the sun.java2d-related system properties e.g.:
System.setProperty("sun.java2d.opengl", "true");
System.setProperty("sun.java2d.d3d", "false");
System.setProperty("sun.java2d.noddraw", "false");


Without setting them, there is no warning whatsoever to be seen. No VM arguments are needed.

The greater problem still arises when using a recent java version (e.g. version 17): "<local3>" (java3d version 1.6) or "awtConfig" (java3d version 1.7) are null and so it is not possible to create a Canvas3D at all.

If I understand correctly, there is no extension mechanism since java version 9. Nevertheless the program still runs correctly in for example version 11, so I don't understand your claim. I would expect it to not work at all from version 9 and on...

Anyway, do you have an idea, how java3d could be used with a recent java version? Is it even possible? If not, might it be fixed in a future release of java3d?
Reply | Threaded
Open this post in threaded view
|

Re: getAWTgraphicsconfiguration() causes NPE error

Oskarnaugh
Hi gouessej,
I managed to make it work. Yout suggestion of adding --add-opens=java.desktop/sun.awt=ALL-UNNAMED to the VM arguments did indeed solve the problem. It was entirely my mistake trying to understand where to put it in IntelliJ IDEA. Thank you very much and appologize for my mistake.
The only thing that I haven't managed is to get rid of the warning messages when setting the system properties.
Reply | Threaded
Open this post in threaded view
|

Re: getAWTgraphicsconfiguration() causes NPE error

Oskarnaugh
Apparently the warnings show on for example JDK version 11 but not in the 17...
Reply | Threaded
Open this post in threaded view
|

Re: getAWTgraphicsconfiguration() causes NPE error

gouessej
Administrator
In reply to this post by Oskarnaugh
Hello

Thank you for your feedback. Actually, as you had still the same warnings caused by reflective accesses, it seemed to indicate that the addition of --add-opens didn't have the expected effect. Please can you tell us where you put --add-opens into IntelliJ? The wiki provides some information for other major IDEs including Apache NetBeans and Eclipse.

On the long term, we'll probably have to provide modules with the necessary information at the right place in order to drive "--add-opens" useless but if some internal classes disappear, we'll have to find another solution.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: getAWTgraphicsconfiguration() causes NPE error

Oskarnaugh
Hi

I took a look at the --add-opens VM-options and managed to make all warnings disappear.
It was necessary to add both options:
--add-opens java.desktop/sun.awt=ALL-UNNAMED
--add-opens java.desktop/sun.java2d.opengl=ALL-UNNAMED

Maybe more options are needed for other things but they seem to work as intended.


To add them in IntelliJ:
1. Open 'Edit Run/Debug configurations' dialog
2. VM options are hidden by default. To add them press "Alt+V" or select "Modify Options -> Add VM Options"
3. Finally write the necessary VM-options sepparated by a space

And that's it! One can totally use Java3D versions 1.6 and 1.7 with the latest JDK version (I also tested version 18). Thank you very much for your support and your time.
Reply | Threaded
Open this post in threaded view
|

Re: getAWTgraphicsconfiguration() causes NPE error

Oskarnaugh
This post was updated on .
Notice than in JDK version 17, I only needed the option --add-opens java.desktop/sun.awt=ALL-UNNAMED to make it run.
The illegal reflective access warnings that showed up when setting the java2d system properties didn't appear in this version but they did in version 11, so check which ones are needed depending on your target JDK