1
votes

How come this works fine:

Vector2[] vertexArray = new Vector2[3];
vertexArray[0] = new Vector2(0f, 0f);
vertexArray[1] = new Vector2(1f, 1f);
vertexArray[2] = new Vector2(2f, 5f);

polygonShape.set(vertexArray);

and this gives a runtime error

Vector2[] vertexArray = new Vector2[3];
vertexArray[0] = new Vector2(0f, 0f);
vertexArray[1] = new Vector2(1f, 1f);
vertexArray[2] = new Vector2(2f, 2f);

polygonShape.set(vertexArray);

Error:

AL lib: (EE) alc_cleanup: 1 device not closed
Assertion failed!

Program: C:\Program Files\Java\jre1.8.0_25\bin\javaw.exe
File: /var/lib/jenkins/workspace/libgdx/extensions/gdx-box2d/gdx-box2d/jni/Box2D/Collision/Shapes/b2PolygonShape.cpp, Line 223

Expression: false

It does not make any sense. First code works fine and the triangle is drawn, but the second code does not. Can someone please explain what I'm doing wrong...

1
Is this error happen in all program runs, or is it one-time exception? - dreamsComeTrue
Did you already used that polygonshape ? - Boldijar Paul
The chances that the code works are 50% and the only thing I am changing are the coordinates. For example, [(0,0), (1,1), (2,5)] does work, but [(0,0), (1,1), (2,3)] does not. - user1176999

1 Answers

3
votes

The vertices (0,0), (1,1), (2,2) are all in a straight line - they don't make a polygon. This causes an assertion to trigger, as shown in the error message (b2PolygonShape.cpp, Line 223)