What steps will reproduce the problem?
1. Create a new Polygon() using the empty constructor. This initializes
vertex[MAX_VERTEX_COUNT]. (The constructor that takes vertices as its argument
initializes it to length (vertices.length / 2)).
2. (optional) Add some vertices with addVertex(*).
3. Call polygon.getBufferObject() (or some other action that triggers
getBufferObject(), such as creating a PolygonSprite based on that Polygon.)
What is the expected output?
getBufferObject() should be able to create a buffer successfully.
What do you see instead?
getBufferObject() throws a NullPointerException, because it is iterating over
the vertices based on the length of the vertex[] array rather than based on
vertexCount. Since the no-argument constructor initializes a large empty array
of length MAX_VERTEX_COUNT, a NullPointerException is thrown when it attempts
to access the first element after vertexCount.
What version of Rokon are you using?
2.0.3
On which version of Android are you experiencing this?
2.2 (API 8)
Please provide any additional information below.
Patch to fix this problem:
--- a/src/com/stickycoding/rokon/Polygon.java
+++ b/src/com/stickycoding/rokon/Polygon.java
@@ -85,7 +85,7 @@ public class Polygon {
buffer = new BufferObject(vertexCount * 2);
float[] vertices = new float[vertexCount * 2];
int c = 0;
- for(int i = 0; i < vertex.length; i++) {
+ for(int i = 0; i < vertexCount; i++) {^M
vertices[c++] = vertex[i].getX();
vertices[c++] = vertex[i].getY();
}
Original issue reported on code.google.com by pjleg...@gmail.com on 29 Aug 2010 at 11:45
Original issue reported on code.google.com by
pjleg...@gmail.com
on 29 Aug 2010 at 11:45