Skip to content

Commit 62e2587

Browse files
committed
prevent node-occ to crash when building cones and tori with invalid arguments.
1 parent a9fcaf8 commit 62e2587

7 files changed

Lines changed: 498 additions & 427 deletions

File tree

src/Edge.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ int Edge::createLine(Vertex *start, Vertex *end)
7373
this->setShape(shape);
7474

7575
}
76-
CATCH_AND_RETHROW("Failed to create line");
76+
CATCH_AND_RETHROW_NO_RETURN("Failed to create line");
7777

7878
return 1;
7979
}
@@ -97,7 +97,7 @@ int Edge::createArc(Vertex *start, Vertex *end, const gp_Pnt& center)
9797
this->setShape(BRepBuilderAPI_MakeEdge(arc, start->vertex(), end->vertex()));
9898

9999
}
100-
CATCH_AND_RETHROW("Failed to create arc");
100+
CATCH_AND_RETHROW_NO_RETURN("Failed to create arc");
101101
return 1;
102102
}
103103

@@ -110,7 +110,7 @@ int Edge::createArc3P(Vertex *start, Vertex *end, const gp_Pnt& aPoint)
110110
GC_MakeArcOfCircle arc(aP1, aP2, aP3);
111111
this->setShape(BRepBuilderAPI_MakeEdge(arc.Value(), start->vertex(), end->vertex()));
112112
}
113-
CATCH_AND_RETHROW("Failed to create arc");
113+
CATCH_AND_RETHROW_NO_RETURN("Failed to create arc");
114114
return 1;
115115
}
116116

@@ -128,7 +128,7 @@ int Edge::createCircle(const gp_Pnt& center, const gp_Dir& normal, double radius
128128
this->setShape(BRepBuilderAPI_MakeEdge(circle));
129129

130130
}
131-
CATCH_AND_RETHROW("Failed to create circle");
131+
CATCH_AND_RETHROW_NO_RETURN("Failed to create circle");
132132
return 1;
133133
}
134134

src/Face.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ bool Face::buildFace(std::vector<Wire*>& wires)
123123
}
124124

125125
}
126-
CATCH_AND_RETHROW("Failed to create a face");
126+
CATCH_AND_RETHROW_NO_RETURN("Failed to create a face");
127127
return true;
128128
}
129129

@@ -200,7 +200,7 @@ v8::Handle<v8::Object> Face::createMesh(double factor, double angle, bool qualit
200200
mesh->extractFaceMesh(this->face(), qualityNormals);
201201
mesh->optimize();
202202

203-
} CATCH_AND_RETHROW("Failed to mesh solid ");
203+
} CATCH_AND_RETHROW_NO_RETURN("Failed to mesh solid ");
204204
return scope.Escape(theMesh);
205205
}
206206

src/NodeV8.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,20 @@ inline const char* ToCString(const v8::String::Utf8Value& value)
161161
catch(Standard_Failure& ) { \
162162
Handle_Standard_Failure e = Standard_Failure::Caught(); \
163163
Standard_CString msg = e->GetMessageString(); \
164-
std::cerr << "C++ exception in OCC "<< msg << std::endl; \
164+
std::cerr << "C++ exception in OCC "<< msg << " " << message << std::endl; \
165165
if (msg == NULL || strlen(msg) < 1) { \
166166
msg = message; \
167167
} \
168-
Nan::ThrowError(msg); \
168+
Nan::ThrowError(msg); \
169169
} \
170170

171+
#define CATCH_AND_RETHROW2(message) \
172+
catch(Standard_Failure& ) { \
173+
info.GetReturnValue().Set(v8::Local<v8::Object>()); \
174+
return Nan::ThrowError(""); \
175+
}
176+
177+
#define CATCH_AND_RETHROW_NO_RETURN(message) \
178+
catch(Standard_Failure& ) { \
179+
Nan::ThrowError(""); \
180+
}

0 commit comments

Comments
 (0)