JY2k
JY2k

Reputation: 2909

android Canvas.drawVertices crashing no exception

I'm trying to draw a quadrilateral using Canvas drawVertices method. It crashes every time with this line :

private final float[] verts = new float[] {
        0, 0,                   // 0 Top left
        0, 800f,                // 1 Bottom left
        480f, 800f,             // 2 Bottom right
        480f,0f                 // 3 Top right
    };
/* Order to draw the vertices */
private short[] indices = { 0, 1, 2, 0, 2, 3 };
private final int[] colors = new int[] {
        Color.parseColor("#75AADB"),
        Color.parseColor("#75AADB"),
        Color.parseColor("#75AADB"),
        Color.parseColor("#75AADB"),
        Color.parseColor("#75AADB"),
        Color.parseColor("#75AADB")
};

And finally I call the actual draw method:

paint.setStyle(Style.FILL);
    paint.setColor(Color.RED);

canvas.drawVertices(Canvas.VertexMode.TRIANGLES, verts.length, verts, 0, null, 0, colors, 0, indices, 0, indices.length, paint);

Upvotes: 0

Views: 238

Answers (1)

Kuno
Kuno

Reputation: 3503

Late, but try adding two Color.parseColor("#75AADB") to your colors array. verts.length must be equals colors.length

Upvotes: 1

Related Questions