Skip to content
This repository was archived by the owner on Dec 28, 2024. It is now read-only.

Commit 4cb3da6

Browse files
committed
NPE fixed
Replaced instance methods with static Path.OutRec.parseFirstLeft(..) and Path.OutPt.getPointCount(..) methods to handle null instances.
1 parent c7fe008 commit 4cb3da6

2 files changed

Lines changed: 18 additions & 19 deletions

File tree

Clipper/src/de/lighti/clipper/DefaultClipper.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ private Path.OutPt addOutPt( Edge e, LongPoint pt ) {
707707
//OutRec.Pts is the 'Left-most' point & OutRec.Pts.Prev is the 'Right-most'
708708
final Path.OutPt op = outRec.getPoints();
709709
final boolean ToFront = e.side == Edge.Side.LEFT;
710-
LOGGER.finest( "op=" + op.getPointCount() );
710+
LOGGER.finest( "op=" + Path.OutPt.getPointCount( op ) );
711711
LOGGER.finest( ToFront + " " + pt + " " + op.getPt() );
712712
if (ToFront && pt.equals( op.getPt() )) {
713713
return op;
@@ -764,10 +764,10 @@ else if (isOutRec1RightOfOutRec2( outRec2, outRec1 )) {
764764
final Path.OutPt p2_lft = outRec2.getPoints();
765765
final Path.OutPt p2_rt = p2_lft.prev;
766766

767-
LOGGER.finest( "p1_lft.getPointCount() = " + p1_lft.getPointCount() );
768-
LOGGER.finest( "p1_rt.getPointCount() = " + p1_rt.getPointCount() );
769-
LOGGER.finest( "p2_lft.getPointCount() = " + p2_lft.getPointCount() );
770-
LOGGER.finest( "p2_rt.getPointCount() = " + p2_rt.getPointCount() );
767+
LOGGER.finest( "p1_lft.getPointCount() = " + Path.OutPt.getPointCount( p1_lft ) );
768+
LOGGER.finest( "p1_rt.getPointCount() = " + Path.OutPt.getPointCount( p1_rt ) );
769+
LOGGER.finest( "p2_lft.getPointCount() = " + Path.OutPt.getPointCount( p2_lft ) );
770+
LOGGER.finest( "p2_rt.getPointCount() = " + Path.OutPt.getPointCount( p2_rt ) );
771771

772772
//join e2 poly onto e1 poly and delete pointers to e2 ...
773773
if (e1.side == Edge.Side.LEFT) {
@@ -899,7 +899,7 @@ private void buildResult( Paths polyg ) {
899899
continue;
900900
}
901901
Path.OutPt p = outRec.getPoints().prev;
902-
final int cnt = p.getPointCount();
902+
final int cnt = Path.OutPt.getPointCount( p );
903903
LOGGER.finest( "cnt = " + cnt );
904904
if (cnt < 2) {
905905
continue;
@@ -919,7 +919,7 @@ private void buildResult2( PolyTree polytree ) {
919919
//add each output polygon/contour to polytree ...
920920
for (int i = 0; i < polyOuts.size(); i++) {
921921
final OutRec outRec = polyOuts.get( i );
922-
final int cnt = outRec.getPoints().getPointCount();
922+
final int cnt = Path.OutPt.getPointCount( outRec.getPoints() );
923923
if (outRec.isOpen && cnt < 2 || !outRec.isOpen && cnt < 3) {
924924
continue;
925925
}
@@ -1240,7 +1240,7 @@ else if (outRec.isOpen) {
12401240

12411241
private void fixupFirstLefts1( OutRec OldOutRec, OutRec NewOutRec ) {
12421242
for (OutRec outRec : polyOuts) {
1243-
final OutRec firstLeft = outRec.firstLeft.parseFirstLeft();
1243+
final OutRec firstLeft = Path.OutRec.parseFirstLeft( outRec.firstLeft );
12441244
if (outRec.getPoints() != null && firstLeft == OldOutRec) {
12451245
if (poly2ContainsPoly1( outRec.getPoints(), NewOutRec.getPoints() )) {
12461246
outRec.firstLeft = NewOutRec;
@@ -1260,7 +1260,7 @@ private void fixupFirstLefts2( OutRec innerOutRec, OutRec outerOutRec ) {
12601260
if (outRec.getPoints() == null || outRec == outerOutRec || outRec == innerOutRec) {
12611261
continue;
12621262
}
1263-
final OutRec firstLeft = outRec.firstLeft.parseFirstLeft();
1263+
final OutRec firstLeft = Path.OutRec.parseFirstLeft( outRec.firstLeft );
12641264
if (firstLeft != orfl && firstLeft != innerOutRec && firstLeft != outerOutRec) {
12651265
continue;
12661266
}
@@ -1280,7 +1280,7 @@ else if (outRec.firstLeft == innerOutRec || outRec.firstLeft == outerOutRec) {
12801280
private void fixupFirstLefts3( OutRec oldOutRec, OutRec newOutRec ) {
12811281
//same as FixupFirstLefts1 but doesn't call Poly2ContainsPoly1()
12821282
for (OutRec outRec : polyOuts) {
1283-
final OutRec firstLeft = outRec.firstLeft.parseFirstLeft();
1283+
final OutRec firstLeft = Path.OutRec.parseFirstLeft( outRec.firstLeft );
12841284
if (outRec.getPoints() != null && firstLeft == oldOutRec) {
12851285
outRec.firstLeft = newOutRec;
12861286
}

Clipper/src/de/lighti/clipper/Path.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,15 @@ else if (p.getPt().getY() == pp.getPt().getY() && p.getPt().getX() <= pp.getPt()
157157
return pp;
158158
}
159159

160-
public int getPointCount() {
161-
160+
public static int getPointCount( OutPt pts ) {
161+
if (pts == null) return 0;
162162
int result = 0;
163-
Path.OutPt p = this;
163+
OutPt p = pts;
164164
do {
165165
result++;
166166
p = p.next;
167167
}
168-
while (p != this && p != null);
168+
while (p != pts);
169169
return result;
170170
}
171171

@@ -237,12 +237,11 @@ public Path.OutPt getPoints() {
237237
return pts;
238238
}
239239

240-
public OutRec parseFirstLeft() {
241-
OutRec ret = this;
242-
while (ret != null && ret.pts == null) {
243-
ret = ret.firstLeft;
240+
public static OutRec parseFirstLeft( OutRec firstLeft ) {
241+
while (firstLeft != null && firstLeft.getPoints() == null) {
242+
firstLeft = firstLeft.firstLeft;
244243
}
245-
return ret;
244+
return firstLeft;
246245
}
247246

248247
public void setPoints( Path.OutPt pts ) {

0 commit comments

Comments
 (0)