mbrlabs/Mundus

NullPointerException on build.

justinmeister opened this issue · 14 comments

I tried building the project from the command line and after the dependencies were downloaded, I got a NullPointerException. Here is the full message:

[08:34][Fatal] java.lang.NullPointerException
at com.mbrlabs.mundus.core.Mundus.dispose(Mundus.java:238)
at com.mbrlabs.mundus.Editor.dispose(Editor.java:234)
at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window.dispose(Lwjgl3Window.java:281)
at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.cleanup(Lwjgl3Application.java:153)
at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.<init>(Lwjgl3Application.java:104)
at com.mbrlabs.mundus.Main.main(Main.java:51)

When dispose is called, goPicker, toolManager, commandHistory, and projectManager are null. When I tried to comment out those dispose() calls, I got this error:

[08:35][Fatal] java.lang.IllegalStateException: frame buffer couldn't be constructed: incomplete     attachment
at com.badlogic.gdx.graphics.glutils.GLFrameBuffer.build(GLFrameBuffer.java:223)
at com.badlogic.gdx.graphics.glutils.GLFrameBuffer.<init>(GLFrameBuffer.java:118)
at com.badlogic.gdx.graphics.glutils.FrameBuffer.<init>(FrameBuffer.java:57)
at com.badlogic.gdx.graphics.glutils.FrameBuffer.<init>(FrameBuffer.java:45)
at com.mbrlabs.mundus.tools.picker.BasePicker.<init>(BasePicker.java:40)
at com.mbrlabs.mundus.tools.picker.GameObjectPicker.<init>(GameObjectPicker.java:39)
at com.mbrlabs.mundus.core.Mundus.init(Mundus.java:105)
at com.mbrlabs.mundus.Editor.create(Editor.java:83)
at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window.initializeListener(Lwjgl3Window.java:272)
at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window.update(Lwjgl3Window.java:239)
at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.loop(Lwjgl3Application.java:127)
at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.<init>(Lwjgl3Application.java:97)
at com.mbrlabs.mundus.Main.main(Main.java:51)

[08:35][Fatal] Uncaught exception occurred, error report will be saved

I don't know enough about Libgdx or this project to fix the bug but hopefully it can be fixed. This happened on macOS.

Hello justinmeister,

thanks for the report. Unfortunally i don't have a mac to test this, but i think i know what causes this issue. In BasePicker.java i create a FrameBufferObject, that is used for offscreen rendering.
Generally you initialize it with the dimensions of the device screen, but on some devices the graphics card can't handle that. That is what your second stacktrace says.
The NPE occurs, because everything that should be initialized after the first FBO exception, is null (dispose gets called when the programs exits).

I just pushed a patch, that uses BackBuffer dimensions instead of logical pixels. I hope this solves your issue.

Hmm, I tried to build after updating the project and I still get the second error message that says
[Fatal] java.lang.IllegalStateException: frame buffer couldn't be constructed: incomplete attachment

The error is exactly the same as before (the second one, not the nullpointerException).

ok, can you replace the BasePicker.java constructor with this and try again?

int width = (int)(Gdx.graphics.getBackBufferWidth() * 0.8);
int height = (int)(Gdx.graphics.getBackBufferHeight() * 0.8);

fbo = new FrameBuffer(Pixmap.Format.RGBA8888, width, height, true);

You may have to tweak the scale value a bit, but this should actually work..
See this discussion on StackOverflow

Also, do you have multiple monitors?

So it didn't work, but I got some more clues.

Both Gdx.graphics.getBackBufferWidth() and Gdx.graphics.getBackBufferHeight() are returning 0 instead of the screen dimensions. I'm not really sure why. Just out of curiosity, I hard coded the pixel dimensions of my monitor as arguments for the frameBuffer. This is the result I got:

:editor:processResources
:editor:classes
:editor:run
[12:54][Info] Started: 16-06-28
[12:54][Debug] Disposing project current null
> Building 87% > :editor:run

It ended up getting stuck on "Building 87%" and I had to stop the process.

I do not have multiple monitors.

Ok, so hardcoding the dimensions fixed the issue.
Can you please provide these values along with the output you get when running this:

System.out.println("width: " + Gdx.graphics.getWidth());
System.out.println("height: " + Gdx.graphics.getHeight());
System.out.println("bb width: " + Gdx.graphics.getBackBufferWidth());
System.out.println("bb height: " + Gdx.graphics.getBackBufferHeight());

It's not stuck, it's running Mundus. editor:run builds and executes the project, that's because it's "stuck". Does the Mundus window not open?

Here is the output:

:editor:processResources
:editor:classes
:editor:run
[13:24][Info] Started: 16-06-28
width: 0
height: 0
bb width: 0
bb height: 0
width: 0
height: 0
bb width: 0
bb height: 0
[13:24][Debug] Disposing project current null
> Building 87% > :editor:run

The Mundus window doesn't open. An java executable is running but no window is shown. It makes my fan run pretty hard though.

Thanks!
Well, that's interesting...everything 0. This also explains the original issue regarding the Fbo.
Just to make sure: you are querying the dimensions after Gdx is inizialized, not inside Main, right?

I put the System.out.println() statements in the BasePicker constructor. I'm assuming at that point Gdx is supposed to be initialized.

Yes, that's alright. This might be a libGDX + LWJGL3 backend + mac issue.
Just one last thing: inside Main.java after the DisplayMode is fetched, do this:

System.out.println("width: " + dm.width);
System.out.println("height: " + dm.height);

A hotfix might also be to set the initial dimensions manually:

config.setWindowedMode(1200, 600);

So I got:

width: 1440
height: 900

in the console for the dm.width and dm.height.

Interestingly enough, hardcoding the config.setWindowedMode(1200, 600) got the Mundus window to open fine. getBackBufferWidth and getBackBufferHeight seems to be working fine now. Their outputs are now 1200, and 600.

Good, thanks for figuring that out!
I think this happens if width and height are both set to their maximums.

I just commit a fix. Can you verify that this works?

The latest commit does not work, I got the error:

[14:46][Error] FBO dimensions 100%: frame buffer couldn't be constructed: incomplete attachment
[14:46][Error] FBO dimensions 90%: frame buffer couldn't be constructed: incomplete attachment
[14:46][Error] FBO dimensions 100%: frame buffer couldn't be constructed: incomplete attachment
[14:46][Error] FBO dimensions 90%: frame buffer couldn't be constructed: incomplete attachment
[14:47][Debug] Disposing project current null

However, I tweaked the setWindowedMethod() and found that 0.88 for height and width was the highest without an error:

config.setWindowedMode((int) (dm.width*0.88f), (int) (dm.height*0.88f));

After that change, it worked fine.

This behaviour is really annoying. Anyway, this should be fixed now.
Thanks for the great help ;)

Yep, works fine now.