Crash in fillPolygon() on iOS

36 views
Skip to first unread message

Timo van de Put

unread,
Apr 1, 2014, 4:42:44 PM4/1/14
to codenameone...@googlegroups.com
My app draws multiple filled polygons using the code below:

 private void fillPolygon(Graphics g, List<Point> points) {
   
int[] arrayX = new int[points.size()];
   
int[] arrayY = new int[points.size()];
   
int i = 0;
   
for (Point p : points) {
     arrayX
[i] = p.getX();
     arrayY
[i] = p.getY();
     i
++;
   
}
   g
.fillPolygon(arrayX, arrayY, points.size());
 
}


This works perfectly on various Android devices and the simulator, but it sometimes crashes on my iOS 7 iPad Mini.
Interestingly, the crash happens only for some shapes but such a "bad" shape will crash the app every time.
Skipping just the fillPolygon for a known "bad" shape prevents the crash from happening.

When the crash occurs, the component that is being drawn is completely replaced by what appears to be vertically repeated copies of some internal buffer.
The app freezes and does not raise a runtime exception. Double clicking the Home button and then swiping the app up is the only way to close it.

Is there a known issue/limitation with fillPolygon on iOS, or does anybody have any ideas what may be causing the crash?

Thanks for your suggestions

Shai Almog

unread,
Apr 2, 2014, 1:12:44 AM4/2/14
to codenameone...@googlegroups.com
Is there an exception in the simulator if you draw a "bad" polygon?
Do you use the unsafe mode on iOS?

Timo van de Put

unread,
Apr 2, 2014, 12:29:41 PM4/2/14
to codenameone...@googlegroups.com
Hi Shai,


On Wednesday, April 2, 2014 7:12:44 AM UTC+2, Shai Almog wrote:
Is there an exception in the simulator if you draw a "bad" polygon?
Do you use the unsafe mode on iOS?

I have never seen any exception in the simulator or on any Android device while drawing these polygons.
This is why I find it very suspicious that this is now happening on my iPad mini.

No build flags are defined, so the iOS build does not use unsafe mode.

Some more details:

The control fills half the Form, and when it crashes it shows a vertically repeating pattern of the screen part above the component. (The title bar and a text field with some space in between.)
When I rotate the screen after the crash, the component is replaced by background and the screen is a stretched version of the previous screen.

This is an example of a "bad" polygon that caused a crash: (576,382), (576,195), (579,195), (582,195), (585,195), (589,195), (589,195)
When I skip the fillPolygon call for this specific set of points, the crash does not take place anymore.

I now suspect something goes wrong inside the fillPolygon function, although I have not seen any reports of this api failing before.

Any suggestions what else I could do to help find the cause?

Shai Almog

unread,
Apr 2, 2014, 1:50:57 PM4/2/14
to codenameone...@googlegroups.com
Hi,
so a hello world that overrides paint and invokes this fill polygon will crash?
If you can attach such a test case to an issue I'll try to get to that. I'm not sure how relevant this will be since we are replacing out rendering layer in iOS with a new implementation so we will have a brand new set of bugs to deal with.

Timo van de Put

unread,
Jul 16, 2014, 11:17:35 AM7/16/14
to codenameone...@googlegroups.com
Hi Shai,

I was curious to find out if my mysterious iOS app crash inside fillPolygon() is now solved by the new pipeline...

But building with ios.newPipeline=true resulted in exactly the same crash as before.  :-(

I am building and drawing a polygon from a List<Point> using this code:

private void fillPolygon(Graphics g, List<Point> points) {
if (points.size() <= 2)
return;
int[] arrayX = new int[points.size()];
int[] arrayY = new int[points.size()];
int i = 0;
for (Point p : points) {
arrayX[i] = p.getX();
arrayY[i] = p.getY();
i++;
}
g.fillPolygon(arrayX, arrayY, arrayX.length);
}

An example polygon causing a crash is: (576,382), (576,195), (579,195), (582,195), (585,195), (589,195), (589,195)

Sofar I have tried (without success):
  1. Removing any duplicate points in the polygon.
  2. Closing the polygon by appending the start point to the end.
  3. Adding an intermediate point between the start and end.
  4. Using the new rendering pipeline
I still suspect the problem is within the fillPolygon() function, as the crash only occurs for specific polygons.
And the problem does not occur on any Android hardware or the simulator.
Another hint is that replacing fillPolygon() with drawPolygon() solves the crash on iOS (but does not fill the polygon).

Can you spot anything else that could be causing the problem?

Thanks

Shai Almog

unread,
Jul 16, 2014, 11:20:41 AM7/16/14
to codenameone...@googlegroups.com
Hi,
I suggest you use the Shape API which negates the need for fillPolygon and is WAY faster since its hardware accelerated.

Timo van de Put

unread,
Jul 17, 2014, 10:01:40 AM7/17/14
to codenameone...@googlegroups.com
Hi Shai,

On Wednesday, July 16, 2014 5:20:41 PM UTC+2, Shai Almog wrote:
Hi,
I suggest you use the Shape API which negates the need for fillPolygon and is WAY faster since its hardware accelerated.

It finally worked! - You just made my day!!!  :-)

But what I now observe is that on the "right" edge of my polygon a white line appears, while the shape is blue on an orange background.
Adding a drawGraph() call does not remove this line, so it appears to be outside the Graph area.
(I am testing on a non-retina iPad Mini.)

Any ideas how to solve this artefact (that does not appear on Android or the simulator)? 

Thanks

Shai Almog

unread,
Jul 17, 2014, 11:23:19 AM7/17/14
to codenameone...@googlegroups.com
Hi,
might be a bug. Please file an issue.
Reply all
Reply to author
Forward
0 new messages