0

So I'm attempting to use a Particle Effect in my game, however, when I run it, it throws the following exception:

06-16 15:10:46.585 9136-10049/pt.bluecover.wearable3d E/AndroidRuntime: FATAL EXCEPTION: GLThread 78458 Process: pt.bluecover.wearable3d, PID: 9136 java.lang.NullPointerException: Attempt to read from field 'com.badlogic.gdx.graphics.g3d.particles.ParallelArray com.badlogic.gdx.graphics.g3d.particles.ParticleController.particles' on a null object reference at com.badlogic.gdx.graphics.g3d.particles.emitters.Emitter.end(Emitter.java:33) at com.badlogic.gdx.graphics.g3d.particles.ParticleController.end(ParticleController.java:184) at com.badlogic.gdx.graphics.g3d.particles.ParticleController.reset(ParticleController.java:176) at com.badlogic.gdx.graphics.g3d.particles.ParticleEffect.reset(ParticleEffect.java:64) at com.mygdx.game.WristPlotter.create(WristPlotter.java:126) at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:290) at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1550) at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1278)

However, I'm currently following this tutorial, and I believe I've everything identical: 3D Particle Systems - LibGDX

So, what might be wrong? Here's the code:

@Override
    public void create() {

        (...)

        //particle system stuff
        particleSystem = ParticleSystem.get();
        pointSpriteBatch = new PointSpriteParticleBatch();
        pointSpriteBatch.setCamera(cam);
        particleSystem.add(pointSpriteBatch);

        assets = new AssetManager();
        ParticleEffectLoader.ParticleEffectLoadParameter loadParam =
                new ParticleEffectLoader.ParticleEffectLoadParameter(particleSystem.getBatches());
        ParticleEffectLoader loader = new ParticleEffectLoader(new InternalFileHandleResolver());
        assets.setLoader(ParticleEffect.class, loader);
        assets.load(PARTICLE_PATH, ParticleEffect.class, loadParam);
        assets.finishLoading();

        ParticleEffect originalEffect = assets.get(PARTICLE_PATH);
        particles = originalEffect.copy();
        particles.init();
        particleSystem.add(particles);

    }


    @Override
    public void render() {

        (...)

        int width = Gdx.graphics.getWidth();
        int height = Gdx.graphics.getHeight();

        Gdx.gl.glViewport(0, 0, width, height);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

        modelBatch.begin(cam);
        modelBatch.render(instancesMap.values(), environment);
        renderParticleEffects();
        modelBatch.end();

    }

    /**
     * Renders our particle effects.
     * Must be used between modelBatch.begin and modelBatch.end
     */
    private void renderParticleEffects() {
        particleSystem.update(); // technically not necessary for rendering
        particleSystem.begin();
        particleSystem.draw();
        particleSystem.end();
        modelBatch.render(particleSystem);
    }

Anyways, thanks in advance!

EDIT: Someone tagged this as a duplicate of "What is a Null Pointer Exception and how do I fix it". Well, this isn't. That question made a general approach on Null Pointer Exceptions. This one refers to the usage of this particular library, libGDX, and where am I failing to add something that could cause the data structure that stores the particles in a particle system to not have the particle effects I loaded previously...

João Borrego
  • 95
  • 2
  • 12
  • It seems that it is a threading problem. Problems can occur when trying to update the graphics from any thread other than the main one. From your error I can understand that: A GLThread broke because it attempted to do something with a nil variable particles.ParticleController.particles when doing the reset(). Check your code to see if you are trying to access a nil variable, or are trying to update the graphics from a secondary thread – Jose Llausas Jun 16 '16 at 15:18
  • Well, that would be strange, since I'm using the frameworks (LibGDX) abstracted method (meaning I don't handle with anything OpenGL ES directly) and the example project runs just fine, and I ain't doing anything different. – João Borrego Jun 17 '16 at 11:04

0 Answers0