Skip to content

Commit 4b3afe1

Browse files
committed
ensure that the empty polygons do not cause the node invert to crash by
erroring earlier.
1 parent d878e03 commit 4b3afe1

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

src/main/java/eu/mihosoft/vrl/v3d/CSG.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,10 @@ public CSG intersect(CSG csg) {
14191419
}
14201420
// triangulate();
14211421
// csg.triangulate();
1422+
if(getPolygons().size()==0 || csg.getPolygons().size()==0) {
1423+
System.err.println("Error! Intersection is invalid when one CSG has no polygons!");
1424+
return new CSG().historySync(this).historySync(csg);
1425+
}
14221426
Node a = new Node(this.clone().getPolygons());
14231427
Node b = new Node(csg.clone().getPolygons());
14241428
a.invert();

src/main/java/eu/mihosoft/vrl/v3d/CSGClient.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,17 @@ private ArrayList<CSG> performOperation(List<CSG> csgList, CSGRemoteOperation op
131131
* Internal method to perform operations and handle request/response
132132
*/
133133
private ArrayList<CSG> performOperation(List<CSG> csgList, CSGRemoteOperation operation,List<Vector3d> points, PropertyStorage storage) throws Exception {
134+
if (javafx.application.Platform.isFxApplicationThread()) {
135+
RuntimeException runtimeException = new RuntimeException("Network trafic can not run on UI thread");
136+
runtimeException.printStackTrace();
137+
throw runtimeException;
138+
}
134139
ArrayList<CSG> back = null;
135140
SSLSocket socket = (SSLSocket) factory.createSocket(hostname, port);
136141
try {
137142
ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
138143
ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
139-
//System.out.println("Running Operation on server: " + hostname + " " + operation);
144+
//
140145
// Create and send request
141146

142147
ArrayList <CSG> toSend = new ArrayList<CSG>();
@@ -160,6 +165,10 @@ private ArrayList<CSG> performOperation(List<CSG> csgList, CSGRemoteOperation op
160165
// Return results as ArrayList
161166
back=new ArrayList<CSG>();
162167
for(CSG c:response.getCsgList()) {
168+
if(c.getPolygons().size()==0) {
169+
System.out.println("Running Operation on server: " + hostname + " " + operation);
170+
new RuntimeException("Network CSG op resulted in no polygons here ").printStackTrace();
171+
}
163172
CSG historySync = CSG.fromPolygons(c.getPolygons());
164173
back.add( historySync);
165174
for(CSG s:csgList) {
@@ -192,6 +201,8 @@ public static void close() {
192201
}
193202

194203
public static boolean isRunning() {
204+
if(javafx.application.Platform.isFxApplicationThread())
205+
return false;// do not run operation on UI thread
195206
if (isServerCall())
196207
return false;
197208
if (getClient() == null)

src/test/java/eu/mihosoft/vrl/v3d/ServerClientTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public CSG prep(CSG incoming) {
5858
int bpoly1 =b.getPolygons().size();
5959

6060
CSG u1 = a.union( b,c);
61+
CSG i1 = c.intersect(b);
6162
CSG d1 = a.difference(b);
6263
CSG t1 = d1.clone().triangulate(true);
6364
ArrayList<CSG> m1 = a.minkowskiHullShape(b);
@@ -73,7 +74,9 @@ public CSG prep(CSG incoming) {
7374
CSG u =a.union( b,c);
7475
if(testPoly(u1,u))
7576
fail();
76-
77+
CSG i0 = c.intersect(b);
78+
if(testPoly(i1,i0))
79+
fail();
7780
CSG d = a.difference(b);
7881
if(testPoly(d1,d))
7982
fail("Difference Step fail , expected "+d1.getPolygons().size()+" got "+d.getPolygons().size());

0 commit comments

Comments
 (0)