libgdx / gdx-video

A libGDX cross platform video rendering extension
Apache License 2.0
145 stars 50 forks source link

Shader is null when using custom mesh in VideoPlayerAndroid.java #45

Closed mattkwilson closed 7 years ago

mattkwilson commented 7 years ago

When you try to create a video player using a custom mesh you get a NullPointerException: Attempt to invoke virtual method 'void com.badlogic.gdx.graphics.glutils.ShaderProgram.begin()' on a null object reference. When I opened up VideoPlayerAndroid.java I noticed shader is never instantiated in the third constructor:

` public VideoPlayerAndroid () { this(new FitViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight())); }

 public VideoPlayerAndroid (Viewport viewport) {
      shader = new ShaderProgram(vertexShaderCode, fragmentShaderCode);
      setupRenderTexture();

      this.viewport = viewport;
      cam = viewport.getCamera();
      mesh = new Mesh(true, 4, 6, VertexAttribute.Position(), VertexAttribute.TexCoords(0));
      //@formatter:off
      mesh.setVertices(new float[] {0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0});
      //@formatter:on
      mesh.setIndices(new short[] {0, 1, 2, 2, 3, 0});
 }

 public VideoPlayerAndroid (Camera cam, Mesh mesh, int primitiveType) {
      this.cam = cam;
      this.mesh = mesh;
      this.primitiveType = primitiveType;
      customMesh = true;
      setupRenderTexture();
 }

`

mattkwilson commented 7 years ago

I submitted a pull request with the fix.