Answer the question
In order to leave comments, you need to log in
What is the FATAL EXCEPTION: GLThread error?
Good evening everyone!
Relatively recently I took up LibGDX and Android development. Work is in progress in Android Studio. When writing a simple application that displays a cube, an error got out
06-24 17:56:23.639 31789-31816/com.room.game E/AndroidRuntime: FATAL EXCEPTION: GLThread 1166
Process: com.room.game, PID: 31789
java.lang.NullPointerException
at com.room.game.main_room.render(main_room.java:44)
at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:459)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1569)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1275)
package com.room.game;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
import com.badlogic.gdx.graphics.g3d.Material;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
public class main_room extends ApplicationAdapter {
public PerspectiveCamera Camera;
public Model model;
public ModelInstance instance;
public ModelBatch modelBatch;
@Override public void create(){
Camera = new PerspectiveCamera( 67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight() );
Camera.position.set( 10f, 10f, 10f );
Camera.lookAt( 0, 0, 0 );
Camera.near = 1f;
Camera.update();
ModelBuilder modelBuilder = new ModelBuilder();
model = modelBuilder.createBox(
5f, 5f, 5f,
new Material( ColorAttribute.createDiffuse( Color.GREEN ) ),
Usage.Position | Usage.Normal
);
instance = new ModelInstance( model );
}
@Override public void render(){
Gdx.gl.glViewport( 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight() );
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT );
modelBatch.begin( Camera );
modelBatch.render( instance );
modelBatch.end();
}
@Override public void dispose(){
modelBatch.dispose();
model.dispose();
}
@Override public void resume(){}
@Override public void resize( int width, int height ){}
@Override public void pause(){}
}
modelBatch.render( instance );
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question