Graphics.fillPolygon(...) ArrayIndexOutOfBoundsException J2ME

39 views
Skip to first unread message

Matthias Bay

unread,
Mar 12, 2015, 4:56:51 AM3/12/15
to codenameone...@googlegroups.com
Hi,

I am sometimes receiving an ArrayIndexOutOfBoundsException when using the fillPolygon-method in Graphics on a j2me-device.
There is no error on the simulator and on android. The arguments are acutally correct.
It seems that this happens only when there are some identical y-coordinates, for example:
g.fillPolygon(new int[]{10, 20, 30}, new int[]{20, 20, 20}, 3);
This throws the exception, it wants to access index 3 (of course only indices 0, 1 and 2 are valid in this case).

Best regards, Matthias

Shai Almog

unread,
Mar 12, 2015, 11:35:16 AM3/12/15
to codenameone...@googlegroups.com
Hi,
I recall something like that existing ages ago. I thought it was fixed but I don't recall specifically.
We don't have any major J2ME accounts so I doubt this will be addressed.

Matthias Bay

unread,
Mar 12, 2015, 5:01:57 PM3/12/15
to codenameone...@googlegroups.com
Hi,

thanks for your answer. I've been looking for a work-around:

Since fillShape(...) is not supported on j2me, this isn't an option.

In my special case it is ok to split the polygon into triangles.
Although I thought fillTriangle will invoke fillPolygon internally, this actually does work, and is even faster.
Even g.fillTriangle(10, 20, 20, 20, 30, 20); works, which should invoke this (and result in an error, but doesn't):

g.fillPolygon(new int[]{10, 20, 30}, new int[]{20, 20, 20}, 3);
So this works, but I don't know why :/
Or doesn't fillTriangle invoke fillPolygon?

Best regards, Matthias

Shai Almog

unread,
Mar 13, 2015, 1:52:50 AM3/13/15
to codenameone...@googlegroups.com
Hi,
fill polygon in the old J2ME port uses drawline and is pretty inefficient. Its very old code dating back to Sun.
Reply all
Reply to author
Forward
0 new messages