polygon.c: Make RectPoly return NULL for zero or negatively sized rectangles
commit6b2b5df93273fd4b6c95ed65679982e39aae8f2d
authorPeter Clifton <pcjc2@cam.ac.uk>
Fri, 26 Aug 2011 13:21:05 +0000 (26 14:21 +0100)
committerPeter Clifton <pcjc2@cam.ac.uk>
Fri, 26 Aug 2011 13:21:05 +0000 (26 14:21 +0100)
tree3b853151b01f46991014a5fddc175ad3fd432787
parent9d40aaacebbdeaff69be5e28bbd2a186bd6bd304
polygon.c: Make RectPoly return NULL for zero or negatively sized rectangles

Previously we would hit an assertion failure, where we could indicate the
problem by returning NULL.

I've hit an issue in which some expose events in the GTK (+GL) HID are
collapsing to a zero-width region on the PCB, and some code is tripping
up on the bad clip polygon produced using RectPoly on the coordinates.
This causes segfaults in the branch which contains code to clip rendering
of the soldermask at the board outline.

We could (and perhaps should) test in the expose handler, but the failure
mode here is not ideal. Since most builds of PCB run with asserts disabled,
the asserts are not hit here and a bad polygon is silently gets created
with no contours. This upsets the polygon algebra routines somewhat, but
returning a NULL (empty) polygon would be fine.
src/polygon.c