Login  Register

Re: How to enable Gluegen (Java3D) on Java 9

Posted by Predrag Bokšić on Dec 05, 2017; 1:21am
URL: https://forum.jogamp.org/How-to-enable-Gluegen-Java3D-on-Java-9-tp4038338p4038380.html

Hello Julien! How are you?

I think that I tested that option among many other options with negative success. I also recompiled the Java3D library for JDK 8 and alternatively, for JDK 9 with some small edits. It does not change anything on any platform, roughly speaking. It failed on OpenJDK... but I destroyed the OpenJDK and recompiled for Ubuntu 16 successfully with OracleJDK. I tried to set the default NOOP renderer, but it failed on all systems. I tried to combine things with the latest Jogamp auto build edition, but it does not change anything.

On MacOS, the execution looks like this:

java -jar project5-test.jar
3D [dev] @VERSION_BASE@-@VERSION_SUFFIX@-experimental @BUILDTIME_VERBOSE@

Initializing 3D runtime system:
    version = @VERSION_BASE@-@VERSION_SUFFIX@-experimental @BUILDTIME_VERBOSE@
    vendor = @IMPL_VENDOR@
    specification.version = 1.6
    specification.vendor = @SPEC_VENDOR@

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by javax.media.j3d.JoglPipeline (file:/Users/lyon/attachments/foo/foo/project5-test/project5-test.jar) to method sun.awt.AppContext.getAppContext()
WARNING: Please consider reporting this to the maintainers of javax.media.j3d.JoglPipeline
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
3D system initialized
    rendering pipeline = JOGL

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00000001349250cc, pid=4008, tid=775
#
# JRE version: Java(TM) SE Runtime Environment (9.0+11) (build 9.0.1+11)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (9.0.1+11, mixed mode, tiered, compressed oops, g1 gc, bsd-amd64)
# Problematic frame:
# C  [libosxapp.dylib+0x20cc]  -[NSApplicationAWT sendEvent:]+0x179


The code for testing looks like this:

import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;

import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.GraphicsConfigTemplate3D;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Enumeration;
import java.util.Properties;

/**
 * Sources
 * <p>
 * https://jogamp.org/deployment/jogamp-current/fat/
 * http://jogamp.org/deployment/java3d/1.6.0-final/
 **/

public class StillCube {
    /**
     * Run parameters
     * -Dj3d.allowNullGraphicsConfig --add-exports=java.base/java.lang=ALL-UNNAMED --add-exports=java.desktop/sun.awt=ALL-UNNAMED --add-exports=java.desktop/sun.java2d=ALL-UNNAMED
     * <p>
     * Problem
     * <p>
     * At least, Canvas3D(gc) turns rogue on some platforms or with some library versions possibly due to Gluegen library.
     * Jogl 2.3.2 has a bug concerning the Mesa drivers, which affects Ubuntu 17.
     * JDK 9 has a bug probably in AWT that affects MacOS.
     * <p>
     * <p>
     * What works well
     * <p>
     * Windows 10, Ubuntu 16, both with JDK 9, and JDK 8 on all platforms.
     */

    // this makes an error java.lang.IllegalArgumentException: Canvas3D: GraphicsConfiguration is not compatible with Canvas3D, but it works!?
    public static GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    public static GraphicsDevice gd = ge.getDefaultScreenDevice();
    public static GraphicsConfiguration gc = gd.getDefaultConfiguration();
    // Java3D vars
    public static Canvas3D c3d;
    public static SimpleUniverse su;

    static {
        try {
            gc = SimpleUniverse.getPreferredConfiguration(); // this works
            // Canvas3D default graphics configuration
            GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D();
            GraphicsConfiguration defaultGcfg = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getBestConfiguration(template);
            gc = defaultGcfg; // this works as well
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static {
        try {
            // -Dj3d.allowNullGraphicsConfig property for Canvas3D
            c3d = new Canvas3D(gc);
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            su = new SimpleUniverse(c3d);
            su.getViewingPlatform().setNominalViewingTransform();
            su.addBranchGraph(getBranchGroup());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public StillCube() {
        try {
            Frame f = new Frame();
            f.setLayout(new BorderLayout());
            Panel p = new Panel(new BorderLayout());
            p.add(BorderLayout.CENTER, c3d);
            f.add(p, BorderLayout.CENTER);
            f.setSize(400, 400);
            f.setVisible(true);
            f.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent windowevent) {
                    f.dispose();
                    System.exit(0);
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static void main(String args[]) {
        System.setProperty("sun.java2d.noddraw", "false"); // should NOT be TRUE!
        System.setProperty("sun.awt.noerasebackground", "true"); // necessary
        //System.setProperty("sun.java2d.opengl", "True"); // no effect
//        System.setProperty("sun.java2d.opengl", "false"); // no effect
//        System.setProperty("sun.java2d.d3d", "false"); // no effect
//        System.setProperty("sun.java2d.d3dtexbpp", "16"); // no effect
//        System.setProperty("sun.java2d.ddoffscreen", "false"); // no effect
//        System.setProperty("sun.java2d.pmoffscreen", "false"); // no effect
//        System.setProperty("sun.java2d.ddforcevram", "false"); // no effect
//        System.setProperty("sun.java2d.accthreshold", "0"); // no effect
//        System.setProperty("sun.java2d.translaccel", "true"); // no effect
//        System.setProperty("sun.java2d.xrender", "True"); // no effect
//        System.setProperty("sun.java2d.opengl.fbobject", "false"); // no effect
        System.setProperty("newt.debug", "all");
        System.setProperty("nativewindow.debug", "all");
        System.setProperty("jogl.debug", "all");


//        final String rendStr = getProperty("j3d.rend");
//        System.out.println("J3D renderer is: " + rendStr);


        final StillCube stillCube = new StillCube();

        //final OneTriangleAWT oneTriangleAWT = new OneTriangleAWT();
        //oneTriangleAWT.main(null);

        //getSystemProperties();


    }


    public static String getProperty(final String prop) {
        return java.security.AccessController.doPrivileged(
                (PrivilegedAction<String>) () -> System.getProperty(prop));
    }


    public static void getSystemProperties() {
        AccessController.doPrivileged(
                (PrivilegedAction) () -> {
                    Properties p = System.getProperties();
                    Enumeration keys = p.keys();
                    while (keys.hasMoreElements()) {
                        String key = (String) keys.nextElement();
                        String value = (String) p.get(key);
                        System.out.println(key + " : " + value);
                    }
                    return null;
                });
    }


    public static BranchGroup getBranchGroup() {
        BranchGroup bg = new BranchGroup();
        try {
            bg.addChild(new ColorCube(.3));
            bg.compile();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bg;
    }
}


Maybe it is time to visit the # Problematic frame:
# C  [libosxapp.dylib+0x20cc]  -[NSApplicationAWT sendEvent:]+0x179 ?