[FIXED] LWJGL3 Engine Crashes rendering "Stanford Bunny"

As the title says. It doesn’t crash when i get it to load and render a basic cube(although the cube’s height is halved). I cant find out what is wrong but i did try placing a couple of sysout’s and have narrowed it down the rendering phase. The thing that is strange is that (according to console output) it does manage to render a couple of times before crashing. If anyone knows any ways to further debug/detect the problem please tell me.

SideNote: Could it be caused by shaders?

EDIT: Uploaded Source: https://github.com/stuart6854/Engine_Source

Project starts at “/VoxelGame_BearEngine/src/org/voxelgame/core/Game.java”.
From their you should be able to see the paths the programs takes.

Relevant Source Below(if want to see more please ask).

OBJLoader.java
http://pastebin.com/Siu5Abn5

Mesh.java
http://pastebin.com/0h2quxkh

Render Method that calls mesh.render
http://pastebin.com/DHjgp9JK

Can we get the console output?

EDIT: We also need the source of the model, or just a few blocks of it, some OBJ models use indices which you don’t have programmed.

OBJ Source: https://graphics.stanford.edu/~mdfisher/Data/Meshes/bunny.obj

Note: the crash is the standard window goes white and popup appears saying it is not responding.

Output:


1
2
3
4
1
2
3
4

That’s an OpenGL Error

EDIT:


        int errorFlag = GL11.glGetError();
        // If an error has occurred...
        if (errorFlag != GL11.GL_NO_ERROR) {
            // Print the error to System.err.
            System.err.println(GLU.gluErrorString(errorFlag));
        }

Try putting that right after you render everything.

Not getting any output from it, just: 1 2 3

note: i put it before the sysout “4” and after the drawelements

Just tried to print something after the glgetError() and before if check but it doesnt. The output that was : 1 2 3 4

If the window doesn’t respond then “Display.update()” isn’t being called. (In LWJGL3 this is “glfwPollEvents() and glfwSwapBuffers(window)”) I looked at your render method, looks like you don’t have a ‘Display.update()’ there.

If you’re calling it in the update method or something, then there’s a bad patch of code that’s taking a long time and is blocking the Display.update call. Try putting a few more syso calls further down the line, the last number outputted should tell you which line of code is slowing/stopping the program.

It gets all the way through a render pass and hits all my sysout’s. i put the display updates methods in render function

After having slept to refresh myself, i have tried to find the problem again. Now after piling sysout’s into my engine core code after every function and the start and end of a fucntions call, i have found the source which seems to be when glfwSwapBuffers is called. What could be causing this?

Would it be useful toe post the whole project?

Uploaded Source: https://github.com/stuart6854/Engine_Source

Project starts at “/VoxelGame_BearEngine/src/org/voxelgame/core/Game.java”.

From their you should be able to see the paths the programs takes.

Other thought is that it has something to do with a simple cube.obj being rendered with a squashed height as well as texture coords being off: http://puu.sh/lV8k1/f8191546da.png

Gonna see if it could be the objreader…

EDIT: :slight_smile: YES! Looks like i have solved it. The problem was in the ObjLoader i was doing some unneccesarry operations on arrays and lists doing conversions which in a way must have muddled the data.

Gonna keep testing make sure it is fine.

Edit: Although not related to crashes, models are definatlybeing squashed height wise: http://puu.sh/lV97C/c8315194e4.png and also the cube image linked before

Have you tried resizing the window? Does it remain a fixed size and squish or does it change interactively with the window.

This could be because your main projection matrix has the wrong aspect ratio. Show me where you set up your primary projection matrix

The cube stays squished height wise when resizing window height.

Window.java(where projection is set in init() method)

Projection.updatePerspective(FOV, getWidth() / getHeight(), Z_NEAR, Z_FAR);

Projection.java(Note: Matrix4f class is from JOML Library)

public class Projection {
	
	public static Matrix4f perspective;
	public static Matrix4f orthogonal;
	
	public static void updatePerspective(float fov, float aspect, float zNear, float zFar){
		Matrix4f matrix = new Matrix4f();

		matrix.identity();
		matrix.perspective(fov, aspect, zNear, zFar);
		
	    perspective = matrix;
	}
	
	public static void updateOrthogonal(float left,float right,float bottom,float top,float near,float far){
		Matrix4f matrix = new Matrix4f().identity();

		matrix.m00 = 2/(right - left);
		matrix.m11 = 2/(top - bottom);
		matrix.m22 = -2/(far - near);
		matrix.m32 = (far+near)/(far - near);
		matrix.m30 = (right+left)/(right -left);
		matrix.m31 = (top + bottom)/(top-bottom);

		orthogonal = matrix;
    }
	
}

Then every render iteration projection is sent to shader:

public void render(Window window, Camera camera, List<GameObject> renderList) {
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// LEAVE
		
		//glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
		
		Matrix4f viewMatrix = MatrixUtils.getViewMatrix(camera);
		
		shaderProgram.bind();
		shaderProgram.setUniform("projectionMatrix", Projection.perspective);
		//shaderProgram.setUniform("camera_pos", camera.getPosition());

		System.out.println("0");
		shaderProgram.setUniform("texture_sampler", 0);
		for(GameObject gameObject : renderList){
			Matrix4f modelViewMatrix = MatrixUtils.getModelViewMatrix(gameObject.getTransform(), viewMatrix);
			shaderProgram.setUniform("modelViewMatrix", modelViewMatrix);
			shaderProgram.setUniform("material", gameObject.getMesh().getMaterial());
			gameObject.getMesh().render();
		}

		System.out.println("6");
		shaderProgram.unbind();
		

		System.out.println("7");
	}

getWidth()/getHeight() is done.at integer precision. Cast to float before the division.

That fixed it, thanks.