V
V
Vladimir Merkulov2016-06-24 18:06:43
Java
Vladimir Merkulov, 2016-06-24 18:06:43

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)

main_room.java source code
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(){}

}

The error pops up on line 44 in
modelBatch.render( instance );
Since, for the time being, I am not a person versed in such subtleties, I would like to hear your reasoning. I found a similar situation in Google stackoverflow.com/questions/30830986/android-studi... however, an attempt to connect what was advised there did not work. Gradle constantly gave out that the file was not found, although I added it as a dependency.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Hakito, 2016-06-24
@StranikS

ModelBatch initialize

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question