NullPointerException when GLWindow.setVisible(true) is called?

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

NullPointerException when GLWindow.setVisible(true) is called?

Pepe1
I'm using this code to init a GLWindow:

        private void initGLWindow()
        {
                glWindow = GLWindow.create(caps);
                glWindow.setTitle(name);
                glWindow.setSize(sizeX, sizeY);
                glWindow.setAutoSwapBufferMode(true);
                glWindow.addGLEventListener(this);
                glWindow.setVisible(true);
        }

Pretty straightforward stuff, however when setVisible(true) is called, it suddenly throws a NullPointerException. Why does this happen? All the other calls succeeded, so it's weird that only that last call yields an exception, right?

Thanks for the help!

EDIT: While I'm asking questions: Is it possible to make a GLWindow non-resizable? I've looked through the documentation, but I couldn't find anything.
Reply | Threaded
Open this post in threaded view
|

Re: NullPointerException when GLWindow.setVisible(true) is called?

Xerxes Rånby
2014-02-07 13:39, Pepe1 [via jogamp] skrev:

> I'm using this code to init a GLWindow:
>
>         private void initGLWindow()
>         {
>                 glWindow = GLWindow.create(caps);
>                 glWindow.setTitle(name);
>                 glWindow.setSize(sizeX, sizeY);
>                 glWindow.setAutoSwapBufferMode(true);
>                 glWindow.addGLEventListener(this);
>                 glWindow.setVisible(true);
>         }
>
> Pretty straightforward stuff, however when setVisible(true) is called, it suddenly throws a NullPointerException. Why does this happen? All the other calls succeeded, so it's weird that only that last call yields an exception, right?
>
> Thanks for the help!

We require some additional information, please read:
http://jogamp.org/wiki/index.php/Jogl_FAQ#Bugreports_.26_Testing

Also the complete sourcecode for your example would be needed since we do not know which caps you use and on which hardware + driver combination you test on.
Please include the stacktrace for the nullpointer exception, since we cant possibly guess.

Cheers
Xerxes
Reply | Threaded
Open this post in threaded view
|

Re: NullPointerException when GLWindow.setVisible(true) is called?

gouessej
Administrator
In reply to this post by Pepe1
Hi

Please provide a complete example and look at our unit tests. Ensure that you use at least JOGL 2.1.4.

I wrote something similar but it works in my case:
https://github.com/Renanse/Ardor3D/blob/master/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtWindow.java

There is a request for enhancement about allowing to make the GLWindow non-resizable, the bug report is attributed to ... me :) It's not yet implemented.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: NullPointerException when GLWindow.setVisible(true) is called?

Pepe1
Right, sorry. Let's try again.

The stack trace:

Exception in thread "main" java.lang.RuntimeException: java.lang.NullPointerException
        at jogamp.newt.DefaultEDTUtil.invokeImpl(DefaultEDTUtil.java:246)
        at jogamp.newt.DefaultEDTUtil.invoke(DefaultEDTUtil.java:160)
        at jogamp.newt.DisplayImpl.runOnEDTIfAvail(DisplayImpl.java:427)
        at jogamp.newt.WindowImpl.runOnEDTIfAvail(WindowImpl.java:1988)
        at jogamp.newt.WindowImpl.setVisible(WindowImpl.java:978)
        at jogamp.newt.WindowImpl.setVisible(WindowImpl.java:983)
        at com.jogamp.newt.opengl.GLWindow.setVisible(GLWindow.java:441)
        at MainWindow.setVisible(MainWindow.java:67)
        at Main.<init>(Main.java:29)
        at Main.main(Main.java:33)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.NullPointerException
        at Menu.drawBackground(Menu.java:37)
        at Menu.display(Menu.java:29)
        at MainWindow.display(MainWindow.java:86)
        at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:665)
        at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:649)
        at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:399)
        at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1119)
        at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:994)
        at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:621)
        at jogamp.opengl.GLAutoDrawableBase.defaultWindowResizedOp(GLAutoDrawableBase.java:244)
        at com.jogamp.newt.opengl.GLWindow.access$200(GLWindow.java:111)
        at com.jogamp.newt.opengl.GLWindow$2.windowResized(GLWindow.java:133)
        at jogamp.newt.WindowImpl.consumeWindowEvent(WindowImpl.java:3516)
        at jogamp.newt.WindowImpl.sendWindowEvent(WindowImpl.java:3454)
        at jogamp.newt.WindowImpl.setVisibleActionImpl(WindowImpl.java:957)
        at jogamp.newt.WindowImpl$VisibleAction.run(WindowImpl.java:969)
        at com.jogamp.common.util.RunnableTask.run(RunnableTask.java:112)
        at jogamp.newt.DefaultEDTUtil$NEDT.run(DefaultEDTUtil.java:369)

(I think) All relevant code:

public class MainWindow implements GLEventListener
{
        private GLWindow        glWindow;
        private GLCapabilities  caps;

        private String          name;
        private int             sizeX;
        private int             sizeY;

        private String          state;

        private State           menu;
        private State           game;

        public MainWindow(String windowName, int x, int y, boolean doubleBuffering, boolean hardwareAcceleration)
        {
                this.name   = windowName;
                this.sizeX  = x;
                this.sizeY  = y;

                setCaps(doubleBuffering, hardwareAcceleration);
                initGLWindow();
        }
        private void setCaps(boolean doubleBuffering, boolean hardwareAcceleration) //I call this with both vars being true
        {
                caps = new GLCapabilities(GLProfile.get(GLProfile.GL2));
                caps.setDoubleBuffered(doubleBuffering);
                caps.setHardwareAccelerated(hardwareAcceleration);
        }
        private void initGLWindow()
        {
                glWindow = GLWindow.create(caps);
                glWindow.setTitle(name);
                glWindow.setSize(sizeX, sizeY);
                glWindow.setAutoSwapBufferMode(true);
                glWindow.addGLEventListener(this);
                glWindow.setVisible(true);

        }
        public void addMouseListener(MouseListener l)
        {
                glWindow.addMouseListener(l);
        }
        public void addKeyListener(KeyListener l)
        {
                glWindow.addKeyListener(l);
        }
        public void setState(String state)
        {
                this.state = state;
        }
        public void setMenu(State menu)
        {
                this.menu = menu;
        }
        public void setGame(State game)
        {
                this.game = game;
        }
}
It's called like so:

public class Main
{
        private MainWindow      window;
        private StateBridger    bridger;
        private Game            game;
        private Menu            menu;
        private UserInput       input;

        public Main()
        {
                window  = new MainWindow("testest", 640, 480, true, true);
                input   = new UserInput(window);
                menu    = new Menu(window);
                game    = new Game(window);
                bridger = new StateBridger(menu, game);

                menu.setBridger(bridger);
                menu.setInput(input);
                game.setBridger(bridger);
                game.setInput(input);

                window.setMenu(menu);
                window.setGame(game);

                menu.start();

                window.setState("Menu");
        }
        public static void main(String[] args)
        {
                new Main();
        }
}

I really appreciate you guys trying to help me.
Reply | Threaded
Open this post in threaded view
|

Re: NullPointerException when GLWindow.setVisible(true) is called?

Sven Gothel
Administrator
On 02/07/2014 03:53 PM, Pepe1 [via jogamp] wrote:

> Right, sorry. Let's try again.
>
> The stack trace:
>
> Caused by: java.lang.NullPointerException
>         at Menu.drawBackground(Menu.java:37)
>         at Menu.display(Menu.java:29)
>         at MainWindow.display(MainWindow.java:86)
>         at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:665)
>         at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:649)
>         at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:399)
Voila, i.e. your Menu.java:37 uses a reference which is NULL.

~Sven


signature.asc (894 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: NullPointerException when GLWindow.setVisible(true) is called?

Xerxes Rånby
In reply to this post by Pepe1
Pepe1 wrote
Right, sorry. Let's try again.

The stack trace:

Exception in thread "main" java.lang.RuntimeException: java.lang.NullPointerException
        at jogamp.newt.DefaultEDTUtil.invokeImpl(DefaultEDTUtil.java:246)
        at jogamp.newt.DefaultEDTUtil.invoke(DefaultEDTUtil.java:160)
        at jogamp.newt.DisplayImpl.runOnEDTIfAvail(DisplayImpl.java:427)
        at jogamp.newt.WindowImpl.runOnEDTIfAvail(WindowImpl.java:1988)
        at jogamp.newt.WindowImpl.setVisible(WindowImpl.java:978)
        at jogamp.newt.WindowImpl.setVisible(WindowImpl.java:983)
        at com.jogamp.newt.opengl.GLWindow.setVisible(GLWindow.java:441)
        at MainWindow.setVisible(MainWindow.java:67)
        at Main.<init>(Main.java:29)
        at Main.main(Main.java:33)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.NullPointerException
        at Menu.drawBackground(Menu.java:37)
        at Menu.display(Menu.java:29)
        at MainWindow.display(MainWindow.java:86)
        at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:665)
        at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:649)
        at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:399)
        at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1119)
        at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:994)
        at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:621)
        at jogamp.opengl.GLAutoDrawableBase.defaultWindowResizedOp(GLAutoDrawableBase.java:244)
        at com.jogamp.newt.opengl.GLWindow.access$200(GLWindow.java:111)
        at com.jogamp.newt.opengl.GLWindow$2.windowResized(GLWindow.java:133)
        at jogamp.newt.WindowImpl.consumeWindowEvent(WindowImpl.java:3516)
        at jogamp.newt.WindowImpl.sendWindowEvent(WindowImpl.java:3454)
        at jogamp.newt.WindowImpl.setVisibleActionImpl(WindowImpl.java:957)
        at jogamp.newt.WindowImpl$VisibleAction.run(WindowImpl.java:969)
        at com.jogamp.common.util.RunnableTask.run(RunnableTask.java:112)
        at jogamp.newt.DefaultEDTUtil$NEDT.run(DefaultEDTUtil.java:369)

(I think) All relevant code:

public class MainWindow implements GLEventListener
{
        private GLWindow        glWindow;
        private GLCapabilities  caps;

        private String          name;
        private int             sizeX;
        private int             sizeY;

        private String          state;

        private State           menu;
        private State           game;

        public MainWindow(String windowName, int x, int y, boolean doubleBuffering, boolean hardwareAcceleration)
        {
                this.name   = windowName;
                this.sizeX  = x;
                this.sizeY  = y;

                setCaps(doubleBuffering, hardwareAcceleration);
                initGLWindow();
        }
        private void setCaps(boolean doubleBuffering, boolean hardwareAcceleration) //I call this with both vars being true
        {
                caps = new GLCapabilities(GLProfile.get(GLProfile.GL2));
                caps.setDoubleBuffered(doubleBuffering);
                caps.setHardwareAccelerated(hardwareAcceleration);
        }
        private void initGLWindow()
        {
                glWindow = GLWindow.create(caps);
                glWindow.setTitle(name);
                glWindow.setSize(sizeX, sizeY);
                glWindow.setAutoSwapBufferMode(true);
                glWindow.addGLEventListener(this);
                glWindow.setVisible(true);

        }
        public void addMouseListener(MouseListener l)
        {
                glWindow.addMouseListener(l);
        }
        public void addKeyListener(KeyListener l)
        {
                glWindow.addKeyListener(l);
        }
        public void setState(String state)
        {
                this.state = state;
        }
        public void setMenu(State menu)
        {
                this.menu = menu;
        }
        public void setGame(State game)
        {
                this.game = game;
        }
}
It's called like so:

public class Main
{
        private MainWindow      window;
        private StateBridger    bridger;
        private Game            game;
        private Menu            menu;
        private UserInput       input;

        public Main()
        {
                window  = new MainWindow("testest", 640, 480, true, true);
                input   = new UserInput(window);
                menu    = new Menu(window);
                game    = new Game(window);
                bridger = new StateBridger(menu, game);

                menu.setBridger(bridger);
                menu.setInput(input);
                game.setBridger(bridger);
                game.setInput(input);

                window.setMenu(menu);
                window.setGame(game);

                menu.start();

                window.setState("Menu");
        }
        public static void main(String[] args)
        {
                new Main();
        }
}

I really appreciate you guys trying to help me.
Still not enough code added to compile and test it.
where is the Menu class?

Caused by: java.lang.NullPointerException
        at Menu.drawBackground(Menu.java:37)

If you have a github account you can upload all the java code needed to compile and run this to a github repository and share that.

cheers
Xerxes
Reply | Threaded
Open this post in threaded view
|

Re: NullPointerException when GLWindow.setVisible(true) is called?

Pepe1
Holy shit I actually missed that NullPointerException at Menu. I feel really stupid right now.

Thanks guys.