diff --git a/src/bsp.cpp b/src/bsp.cpp index bba7265..485902b 100644 --- a/src/bsp.cpp +++ b/src/bsp.cpp @@ -39,7 +39,7 @@ SBsp3 *SBsp3::FromMesh(SMesh *m) { Vector SBsp3::IntersectionWith(Vector a, Vector b) { double da = a.Dot(n) - d; double db = b.Dot(n) - d; - if(da*db > 0) oops(); + ssassert(da*db < 0, "Expected segment to intersect BSP node"); double dab = (db - da); return (a.ScaledBy(db/dab)).Plus(b.ScaledBy(-da/dab)); @@ -104,7 +104,7 @@ void SBsp3::InsertHow(int how, STriangle *tr, SMesh *instead) { more = m; break; } - default: oops(); + default: ssassert(false, "Unexpected BSP insert type"); } return; @@ -144,7 +144,7 @@ void SBsp3::InsertConvexHow(int how, STriMeta meta, Vector *vertex, int n, } break; - default: oops(); + default: ssassert(false, "Unexpected BSP insert type"); } int i; for(i = 0; i < n - 2; i++) { @@ -234,7 +234,7 @@ SBsp3 *SBsp3::InsertConvex(STriMeta meta, Vector *vertex, int cnt, inter[inters++] = vi; } } - if(npos > cnt + 1 || nneg > cnt + 1) oops(); + if(npos > cnt + 1 || nneg > cnt + 1) ssassert(false, "Impossible"); if(!instead) { if(inters == 2) { @@ -320,7 +320,7 @@ void SBsp3::Insert(STriangle *tr, SMesh *instead) { if (!isOn[0]) { a = tr->b; b = tr->c; } else if(!isOn[1]) { a = tr->c; b = tr->a; } else if(!isOn[2]) { a = tr->a; b = tr->b; } - else oops(); + else ssassert(false, "Impossible"); if(!instead) { SEdge se = SEdge::From(a, b); edges = SBsp2::InsertOrCreateEdge(edges, &se, n, tr->Normal()); @@ -344,7 +344,7 @@ void SBsp3::Insert(STriangle *tr, SMesh *instead) { if (isOn[0]) { a = tr->a; b = tr->b; c = tr->c; bpos = isPos[1]; } else if(isOn[1]) { a = tr->b; b = tr->c; c = tr->a; bpos = isPos[2]; } else if(isOn[2]) { a = tr->c; b = tr->a; c = tr->b; bpos = isPos[0]; - } else oops(); + } else ssassert(false, "Impossible"); Vector bPc = IntersectionWith(b, c); STriangle btri = STriangle::From(tr->meta, a, b, bPc); @@ -371,14 +371,14 @@ void SBsp3::Insert(STriangle *tr, SMesh *instead) { if (isNeg[0]) { a = tr->a; b = tr->b; c = tr->c; } else if(isNeg[1]) { a = tr->b; b = tr->c; c = tr->a; } else if(isNeg[2]) { a = tr->c; b = tr->a; c = tr->b; - } else oops(); + } else ssassert(false, "Impossible"); } else if(posc == 1 && negc == 2) { if (isPos[0]) { a = tr->a; b = tr->b; c = tr->c; } else if(isPos[1]) { a = tr->b; b = tr->c; c = tr->a; } else if(isPos[2]) { a = tr->c; b = tr->a; c = tr->b; - } else oops(); - } else oops(); + } else ssassert(false, "Impossible"); + } else ssassert(false, "Impossible"); Vector aPb = IntersectionWith(a, b); Vector cPa = IntersectionWith(c, a); @@ -471,7 +471,7 @@ void SBsp3::DebugDraw(void) { Vector SBsp2::IntersectionWith(Vector a, Vector b) { double da = a.Dot(no) - d; double db = b.Dot(no) - d; - if(da*db > 0) oops(); + ssassert(da*db < 0, "Expected segment to intersect BSP node"); double dab = (db - da); return (a.ScaledBy(db/dab)).Plus(b.ScaledBy(-da/dab)); @@ -547,7 +547,7 @@ void SBsp2::InsertEdge(SEdge *nedge, Vector nnp, Vector out) { } return; } - oops(); + ssassert(false, "Impossible"); } void SBsp2::InsertTriangleHow(int how, STriangle *tr, SMesh *m, SBsp3 *bsp3) { @@ -568,7 +568,7 @@ void SBsp2::InsertTriangleHow(int how, STriangle *tr, SMesh *m, SBsp3 *bsp3) { } break; - default: oops(); + default: ssassert(false, "Unexpected BSP insert type"); } } @@ -614,7 +614,7 @@ void SBsp2::InsertTriangle(STriangle *tr, SMesh *m, SBsp3 *bsp3) { if (isOn[0]) { a = tr->a; b = tr->b; c = tr->c; bpos = isPos[1]; } else if(isOn[1]) { a = tr->b; b = tr->c; c = tr->a; bpos = isPos[2]; } else if(isOn[2]) { a = tr->c; b = tr->a; c = tr->b; bpos = isPos[0]; - } else oops(); + } else ssassert(false, "Impossible"); Vector bPc = IntersectionWith(b, c); STriangle btri = STriangle::From(tr->meta, a, b, bPc); @@ -636,14 +636,14 @@ void SBsp2::InsertTriangle(STriangle *tr, SMesh *m, SBsp3 *bsp3) { if (isNeg[0]) { a = tr->a; b = tr->b; c = tr->c; } else if(isNeg[1]) { a = tr->b; b = tr->c; c = tr->a; } else if(isNeg[2]) { a = tr->c; b = tr->a; c = tr->b; - } else oops(); + } else ssassert(false, "Impossible"); } else if(posc == 1 && negc == 2) { if (isPos[0]) { a = tr->a; b = tr->b; c = tr->c; } else if(isPos[1]) { a = tr->b; b = tr->c; c = tr->a; } else if(isPos[2]) { a = tr->c; b = tr->a; c = tr->b; - } else oops(); - } else oops(); + } else ssassert(false, "Impossible"); + } else ssassert(false, "Impossible"); Vector aPb = IntersectionWith(a, b); Vector cPa = IntersectionWith(c, a); @@ -666,8 +666,8 @@ void SBsp2::InsertTriangle(STriangle *tr, SMesh *m, SBsp3 *bsp3) { } void SBsp2::DebugDraw(Vector n, double d) { - if(fabs((edge.a).Dot(n) - d) > LENGTH_EPS) oops(); - if(fabs((edge.b).Dot(n) - d) > LENGTH_EPS) oops(); + ssassert(fabs((edge.a).Dot(n) - d) < LENGTH_EPS, "Endpoint too close to BSP node plane"); + ssassert(fabs((edge.b).Dot(n) - d) < LENGTH_EPS, "Endpoint too close to BSP node plane"); ssglLineWidth(10); glBegin(GL_LINES); diff --git a/src/clipboard.cpp b/src/clipboard.cpp index a6be420..9055128 100644 --- a/src/clipboard.cpp +++ b/src/clipboard.cpp @@ -42,7 +42,8 @@ hEntity SolveSpaceUI::Clipboard::NewEntityFor(hEntity he) { return cr->newReq.entity(1+i); } } - oops(); + + ssassert(false, "Expected to find entity in some clipboard request"); } void GraphicsWindow::DeleteSelection(void) { @@ -259,7 +260,7 @@ void GraphicsWindow::MenuClipboard(int id) { SS.GW.DeleteSelection(); break; - default: oops(); + default: ssassert(false, "Unexpected menu ID"); } } diff --git a/src/constraint.cpp b/src/constraint.cpp index 6137021..5b70ddb 100644 --- a/src/constraint.cpp +++ b/src/constraint.cpp @@ -730,7 +730,7 @@ void Constraint::MenuConstrain(int id) { SS.ScheduleShowTW(); break; - default: oops(); + default: ssassert(false, "Unexpected menu ID"); } SS.GW.ClearSelection(); diff --git a/src/constrainteq.cpp b/src/constrainteq.cpp index 8acde19..69c9f0b 100644 --- a/src/constrainteq.cpp +++ b/src/constrainteq.cpp @@ -54,7 +54,7 @@ Expr *ConstraintBase::VectorsParallel(int eq, ExprVector a, ExprVector b) { if(eq == 0) return e0; if(eq == 1) return e1; - oops(); + ssassert(false, "Unexpected index of equation"); } Expr *ConstraintBase::PointLineDistance(hEntity wrkpl, hEntity hpt, hEntity hln) @@ -104,7 +104,8 @@ Expr *ConstraintBase::PointPlaneDistance(ExprVector p, hEntity hpl) { Expr *ConstraintBase::Distance(hEntity wrkpl, hEntity hpa, hEntity hpb) { EntityBase *pa = SK.GetEntity(hpa); EntityBase *pb = SK.GetEntity(hpb); - if(!(pa->IsPoint() && pb->IsPoint())) oops(); + ssassert(pa->IsPoint() && pb->IsPoint(), + "Expected two points to measure projected distance between"); if(wrkpl.v == EntityBase::FREE_IN_3D.v) { // This is true distance @@ -182,7 +183,7 @@ void ConstraintBase::ModifyToSatisfy(void) { IdList l = {}; // Generate the equations even if this is a reference dimension GenerateReal(&l); - if(l.n != 1) oops(); + ssassert(l.n == 1, "Expected constraint to generate a single equation"); // These equations are written in the form f(...) - d = 0, where // d is the value of the valA. @@ -735,7 +736,7 @@ void ConstraintBase::GenerateReal(IdList *l) { dir[i] = e->CubicGetStartTangentExprs(); } } else { - oops(); + ssassert(false, "Unexpected entity types for CURVE_CURVE_TANGENT"); } } if(parallel) { @@ -788,7 +789,7 @@ void ConstraintBase::GenerateReal(IdList *l) { case COMMENT: break; - default: oops(); + default: ssassert(false, "Unexpected constraint ID"); } } diff --git a/src/describescreen.cpp b/src/describescreen.cpp index b91993f..759142d 100644 --- a/src/describescreen.cpp +++ b/src/describescreen.cpp @@ -235,7 +235,7 @@ void TextWindow::DescribeSelection(void) { Printf(false, "%FtPOINT AND A CIRCLE"); } else if(ec->type == Entity::ARC_OF_CIRCLE) { Printf(false, "%FtPOINT AND AN ARC"); - } else oops(); + } else ssassert(false, "Unexpected entity type"); Vector p = SK.GetEntity(gs.point[0])->PointGetNum(); Printf(true, " pt at " PT_AS_STR, COSTR(p)); Vector c = SK.GetEntity(ec->point[0])->PointGetNum(); diff --git a/src/drawconstraint.cpp b/src/drawconstraint.cpp index 31139bc..ecec403 100644 --- a/src/drawconstraint.cpp +++ b/src/drawconstraint.cpp @@ -305,7 +305,7 @@ void Constraint::DoEqualRadiusTicks(hEntity he) { double thetaa, thetab, dtheta; circ->ArcGetAngles(&thetaa, &thetab, &dtheta); theta = thetaa + dtheta/2; - } else oops(); + } else ssassert(false, "Unexpected entity type"); Vector d = u.ScaledBy(cos(theta)).Plus(v.ScaledBy(sin(theta))); d = d.ScaledBy(r); @@ -1166,7 +1166,7 @@ s: break; } - default: oops(); + default: ssassert(false, "Unexpected constraint type"); } } diff --git a/src/drawentity.cpp b/src/drawentity.cpp index 39bc085..bfc7116 100644 --- a/src/drawentity.cpp +++ b/src/drawentity.cpp @@ -180,7 +180,7 @@ BBox Entity::GetOrGenerateScreenBBox(bool *hasBBox) { screenBBox.Include(SS.GW.ProjectPoint3(sb->ctrl[i])); } } - } else oops(); + } else ssassert(false, "Expected entity to be a point or have beziers"); // Enlarge the bounding box to consider selection radius. screenBBox.minp.x -= SELECTION_RADIUS; @@ -286,7 +286,7 @@ void Entity::ComputeInterpolatingSpline(SBezierList *sbl, bool periodic) { // The number of unknowns to solve for. int n = periodic ? 3 + ep : ep; - if(n >= MAX_N) oops(); + ssassert(n < MAX_N, "Too many unknowns"); // The number of on-curve points, one more than the number of segments. int pts = periodic ? 4 + ep : 2 + ep; @@ -708,8 +708,7 @@ void Entity::DrawOrGetDistance(void) { // Do nothing; these are drawn with the triangle mesh break; - default: - oops(); + default: ssassert(false, "Unexpected entity type"); } // And draw the curves; generate the rational polynomial curves for diff --git a/src/dsc.h b/src/dsc.h index 76d87b9..9336967 100644 --- a/src/dsc.h +++ b/src/dsc.h @@ -222,7 +222,7 @@ public: } void RemoveLast(int cnt) { - if(n < cnt) oops(); + ssassert(n >= cnt, "Removing more elements than the list contains"); for(int i = n - cnt; i < n; i++) elem[i].~T(); n -= cnt; @@ -281,13 +281,11 @@ public: while(first != last) { int mid = (first + last)/2; H hm = elem[mid].h; + ssassert(hm.v != t->h.v, "Handle isn't unique"); if(hm.v > t->h.v) { last = mid; } else if(hm.v < t->h.v) { first = mid + 1; - } else { - dbp("can't insert in list; is handle %d not unique?", t->h.v); - oops(); } } @@ -300,10 +298,7 @@ public: T *FindById(H h) { T *t = FindByIdNoOops(h); - if(!t) { - dbp("failed to look up item %08x, searched %d items", h.v, n); - oops(); - } + ssassert(t != NULL, "Cannot find handle"); return t; } diff --git a/src/entity.cpp b/src/entity.cpp index 7f4a3a7..3c33522 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -38,7 +38,7 @@ ExprVector EntityBase::VectorGetExprs(void) { case NORMAL_N_ROT_AA: return NormalExprsN(); - default: oops(); + default: ssassert(false, "Unexpected entity type"); } } @@ -55,7 +55,7 @@ Vector EntityBase::VectorGetNum(void) { case NORMAL_N_ROT_AA: return NormalN(); - default: oops(); + default: ssassert(false, "Unexpected entity type"); } } @@ -72,7 +72,7 @@ Vector EntityBase::VectorGetRefPoint(void) { case NORMAL_N_ROT_AA: return SK.GetEntity(point[0])->PointGetNum(); - default: oops(); + default: ssassert(false, "Unexpected entity type"); } } @@ -88,7 +88,7 @@ Vector EntityBase::VectorGetStartPoint(void) { case NORMAL_N_ROT_AA: return SK.GetEntity(point[0])->PointGetNum(); - default: oops(); + default: ssassert(false, "Unexpected entity type"); } } @@ -101,7 +101,7 @@ Expr *EntityBase::CircleGetRadiusExpr(void) { return SK.GetEntity(distance)->DistanceGetExpr(); } else if(type == ARC_OF_CIRCLE) { return Constraint::Distance(workplane, point[0], point[1]); - } else oops(); + } else ssassert(false, "Unexpected entity type"); } double EntityBase::CircleGetRadiusNum(void) { @@ -111,11 +111,11 @@ double EntityBase::CircleGetRadiusNum(void) { Vector c = SK.GetEntity(point[0])->PointGetNum(); Vector pa = SK.GetEntity(point[1])->PointGetNum(); return (pa.Minus(c)).Magnitude(); - } else oops(); + } else ssassert(false, "Unexpected entity type"); } void EntityBase::ArcGetAngles(double *thetaa, double *thetab, double *dtheta) { - if(type != ARC_OF_CIRCLE) oops(); + ssassert(type == ARC_OF_CIRCLE, "Unexpected entity type"); Quaternion q = Normal()->NormalGetNum(); Vector u = q.RotationU(), v = q.RotationV(); @@ -185,9 +185,7 @@ void EntityBase::WorkplaneGetPlaneExprs(ExprVector *n, Expr **dn) { // n dot p - n dot p0 = 0 // so dn = n dot p0 *dn = p0.Dot(*n); - } else { - oops(); - } + } else ssassert(false, "Unexpected entity type"); } bool EntityBase::IsDistance(void) { @@ -199,21 +197,21 @@ double EntityBase::DistanceGetNum(void) { return SK.GetParam(param[0])->val; } else if(type == DISTANCE_N_COPY) { return numDistance; - } else oops(); + } else ssassert(false, "Unexpected entity type"); } Expr *EntityBase::DistanceGetExpr(void) { if(type == DISTANCE) { return Expr::From(param[0]); } else if(type == DISTANCE_N_COPY) { return Expr::From(numDistance); - } else oops(); + } else ssassert(false, "Unexpected entity type"); } void EntityBase::DistanceForceTo(double v) { if(type == DISTANCE) { (SK.GetParam(param[0]))->val = v; } else if(type == DISTANCE_N_COPY) { // do nothing, it's locked - } else oops(); + } else ssassert(false, "Unexpected entity type"); } EntityBase *EntityBase::Normal(void) { @@ -276,7 +274,7 @@ Quaternion EntityBase::NormalGetNum(void) { break; } - default: oops(); + default: ssassert(false, "Unexpected entity type"); } return q; } @@ -308,7 +306,7 @@ void EntityBase::NormalForceTo(Quaternion q) { // Not sure if I'll bother implementing this one break; - default: oops(); + default: ssassert(false, "Unexpected entity type"); } } @@ -364,7 +362,7 @@ ExprQuaternion EntityBase::NormalGetExprs(void) { break; } - default: oops(); + default: ssassert(false, "Unexpected entity type"); } return q; } @@ -428,7 +426,7 @@ void EntityBase::PointForceTo(Vector p) { // Nothing to do; it's a static copy break; - default: oops(); + default: ssassert(false, "Unexpected entity type"); } } @@ -476,7 +474,7 @@ Vector EntityBase::PointGetNum(void) { p = numPoint; break; - default: oops(); + default: ssassert(false, "Unexpected entity type"); } return p; } @@ -525,7 +523,7 @@ ExprVector EntityBase::PointGetExprs(void) { r = ExprVector::From(numPoint); break; - default: oops(); + default: ssassert(false, "Unexpected entity type"); } return r; } @@ -553,7 +551,7 @@ void EntityBase::PointGetExprsInWorkplane(hEntity wrkpl, Expr **u, Expr **v) { } void EntityBase::PointForceQuaternionTo(Quaternion q) { - if(type != POINT_N_ROT_TRANS) oops(); + ssassert(type == POINT_N_ROT_TRANS, "Unexpected entity type"); SK.GetParam(param[3])->val = q.w; SK.GetParam(param[4])->val = q.vx; @@ -592,7 +590,7 @@ Quaternion EntityBase::PointGetQuaternion(void) { q = GetAxisAngleQuaternion(3); } else if(type == POINT_N_ROT_TRANS) { q = Quaternion::From(param[3], param[4], param[5], param[6]); - } else oops(); + } else ssassert(false, "Unexpected entity type"); return q; } @@ -635,7 +633,7 @@ ExprVector EntityBase::FaceGetNormalExprs(void) { r = ExprVector::From(numNormal.vx, numNormal.vy, numNormal.vz); ExprQuaternion q = GetAxisAngleQuaternionExprs(3); r = q.Rotate(r); - } else oops(); + } else ssassert(false, "Unexpected entity type"); return r; } @@ -658,7 +656,7 @@ Vector EntityBase::FaceGetNormalNum(void) { r = Vector::From(numNormal.vx, numNormal.vy, numNormal.vz); Quaternion q = GetAxisAngleQuaternion(3); r = q.Rotate(r); - } else oops(); + } else ssassert(false, "Unexpected entity type"); return r.WithMagnitude(1); } @@ -687,7 +685,7 @@ ExprVector EntityBase::FaceGetPointExprs(void) { r = r.Minus(trans); r = q.Rotate(r); r = r.Plus(trans); - } else oops(); + } else ssassert(false, "Unexpected entity type"); return r; } @@ -712,7 +710,7 @@ Vector EntityBase::FaceGetPointNum(void) { r = numPoint.Minus(trans); r = q.Rotate(r); r = r.Plus(trans); - } else oops(); + } else ssassert(false, "Unexpected entity type"); return r; } @@ -728,9 +726,7 @@ Vector EntityBase::EndpointStart() { return CubicGetStartNum(); } else if(type == ARC_OF_CIRCLE) { return SK.GetEntity(point[1])->PointGetNum(); - } else { - oops(); - } + } else ssassert(false, "Unexpected entity type"); } Vector EntityBase::EndpointFinish() { if(type == LINE_SEGMENT) { @@ -739,9 +735,7 @@ Vector EntityBase::EndpointFinish() { return CubicGetFinishNum(); } else if(type == ARC_OF_CIRCLE) { return SK.GetEntity(point[2])->PointGetNum(); - } else { - oops(); - } + } else ssassert(false, "Unexpected entity type"); } void EntityBase::AddEq(IdList *l, Expr *expr, int index) { diff --git a/src/export.cpp b/src/export.cpp index 8ceefd7..f38f0fc 100644 --- a/src/export.cpp +++ b/src/export.cpp @@ -895,7 +895,7 @@ void SolveSpaceUI::ExportMeshAsThreeJsTo(FILE *f, const std::string &filename, std::string baseFilename = noExtFilename; size_t lastSlash = baseFilename.rfind(PATH_SEP); - if(lastSlash == std::string::npos) oops(); + ssassert(lastSlash != std::string::npos, "Expected at least one path separator"); baseFilename.erase(0, lastSlash + 1); for(size_t i = 0; i < baseFilename.length(); i++) { diff --git a/src/exportstep.cpp b/src/exportstep.cpp index 8e3936c..5f6378c 100644 --- a/src/exportstep.cpp +++ b/src/exportstep.cpp @@ -117,7 +117,7 @@ int StepFileWriter::ExportCurve(SBezier *sb) { } int StepFileWriter::ExportCurveLoop(SBezierLoop *loop, bool inner) { - if(loop->l.n < 1) oops(); + ssassert(loop->l.n >= 1, "Expected at least one loop"); List listOfTrims = {}; diff --git a/src/exportvector.cpp b/src/exportvector.cpp index 3e274c0..b22b763 100644 --- a/src/exportvector.cpp +++ b/src/exportvector.cpp @@ -510,9 +510,7 @@ public: spline->knotslist.push_back(1.0); spline->knotslist.push_back(1.0); spline->knotslist.push_back(1.0); - } else { - oops(); - } + } else ssassert(false, "Unexpected degree of spline"); } void writeSpline(SBezier *sb) { @@ -755,8 +753,7 @@ static std::string MakeStipplePattern(int pattern, double scale, char delimiter, result = ssprintf("%.3f_%.3f", scale * 2.0, scale * 0.5); break; - default: - oops(); + default: ssassert(false, "Unexpected stipple pattern"); } std::replace(result.begin(), result.end(), '_', delimiter); return result; diff --git a/src/expr.cpp b/src/expr.cpp index 52e06b0..f3c8b42 100644 --- a/src/expr.cpp +++ b/src/expr.cpp @@ -284,7 +284,7 @@ int Expr::Children(void) { case ACOS: return 1; - default: oops(); + default: ssassert(false, "Unexpected operation"); } } @@ -293,7 +293,7 @@ int Expr::Nodes(void) { case 0: return 1; case 1: return 1 + a->Nodes(); case 2: return 1 + a->Nodes() + b->Nodes(); - default: oops(); + default: ssassert(false, "Unexpected children count"); } } @@ -353,7 +353,7 @@ double Expr::Eval(void) { case ACOS: return acos(a->Eval()); case ASIN: return asin(a->Eval()); - default: oops(); + default: ssassert(false, "Unexpected operation"); } } @@ -396,7 +396,7 @@ Expr *Expr::PartialWrt(hParam p) { return (From(-1)->Div((From(1)->Minus(a->Square()))->Sqrt())) ->Times(a->PartialWrt(p)); - default: oops(); + default: ssassert(false, "Unexpected operation"); } } @@ -487,13 +487,13 @@ Expr *Expr::FoldConstants(void) { } break; - default: oops(); + default: ssassert(false, "Unexpected operation"); } return n; } void Expr::Substitute(hParam oldh, hParam newh) { - if(op == PARAM_PTR) oops(); + ssassert(op != PARAM_PTR, "Expected an expression that refer to params via handles"); if(op == PARAM && parh.v == oldh.v) { parh = newh; @@ -518,7 +518,7 @@ hParam Expr::ReferencedParams(ParamList *pl) { return NO_PARAMS; } } - if(op == PARAM_PTR) oops(); + ssassert(op != PARAM_PTR, "Expected an expression that refer to params via handles"); int c = Children(); if(c == 0) { @@ -538,7 +538,7 @@ hParam Expr::ReferencedParams(ParamList *pl) { } else { return MULTIPLE_PARAMS; } - } else oops(); + } else ssassert(false, "Unexpected children count"); } @@ -571,7 +571,7 @@ p: case ASIN: return "(asin " + a->Print() + ")"; case ACOS: return "(acos " + a->Print() + ")"; - default: oops(); + default: ssassert(false, "Unexpected operation"); } } @@ -624,7 +624,7 @@ void Expr::Consume(void) { int Expr::Precedence(Expr *e) { if(e->op == ALL_RESOLVED) return -1; // never want to reduce this marker - if(e->op != BINARY_OP && e->op != UNARY_OP) oops(); + ssassert(e->op == BINARY_OP || e->op == UNARY_OP, "Unexpected operation"); switch(e->c) { case 'q': @@ -638,7 +638,7 @@ int Expr::Precedence(Expr *e) { case '+': case '-': return 10; - default: oops(); + default: ssassert(false, "Unexpected operator"); } } @@ -664,7 +664,7 @@ c: case 's': n = (PopOperand()->Times(Expr::From(PI/180)))->Sin(); break; case 'c': n = (PopOperand()->Times(Expr::From(PI/180)))->Cos(); break; - default: oops(); + default: ssassert(false, "Unexpected operator"); } PushOperand(n); } diff --git a/src/file.cpp b/src/file.cpp index fe49590..705510f 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -248,7 +248,7 @@ void SolveSpaceUI::SaveUsingTable(int type) { break; } - default: oops(); + default: ssassert(false, "Unexpected value format"); } fprintf(fh, "\n"); } @@ -415,7 +415,7 @@ void SolveSpaceUI::LoadUsingTable(char *key, char *val) { break; } - default: oops(); + default: ssassert(false, "Unexpected value format"); } break; } @@ -569,7 +569,7 @@ bool SolveSpaceUI::LoadEntitiesFromFile(const std::string &filename, EntityList &(tr.a.x), &(tr.a.y), &(tr.a.z), &(tr.b.x), &(tr.b.y), &(tr.b.z), &(tr.c.x), &(tr.c.y), &(tr.c.z)) != 11) { - oops(); + ssassert(false, "Unexpected Triangle format"); } tr.meta.color = RgbaColor::FromPackedInt((uint32_t)rgba); m->AddTriangle(&tr); @@ -578,7 +578,7 @@ bool SolveSpaceUI::LoadEntitiesFromFile(const std::string &filename, EntityList if(sscanf(line, "Surface %x %x %x %d %d", &(srf.h.v), &rgba, &(srf.face), &(srf.degm), &(srf.degn)) != 5) { - oops(); + ssassert(false, "Unexpected Surface format"); } srf.color = RgbaColor::FromPackedInt((uint32_t)rgba); } else if(StrStartsWith(line, "SCtrl ")) { @@ -588,7 +588,7 @@ bool SolveSpaceUI::LoadEntitiesFromFile(const std::string &filename, EntityList if(sscanf(line, "SCtrl %d %d %lf %lf %lf Weight %lf", &i, &j, &(c.x), &(c.y), &(c.z), &w) != 6) { - oops(); + ssassert(false, "Unexpected SCtrl format"); } srf.ctrl[i][j] = c; srf.weight[i][j] = w; @@ -600,7 +600,7 @@ bool SolveSpaceUI::LoadEntitiesFromFile(const std::string &filename, EntityList &(stb.start.x), &(stb.start.y), &(stb.start.z), &(stb.finish.x), &(stb.finish.y), &(stb.finish.z)) != 8) { - oops(); + ssassert(false, "Unexpected TrimBy format"); } stb.backwards = (backwards != 0); srf.trim.Add(&stb); @@ -615,7 +615,7 @@ bool SolveSpaceUI::LoadEntitiesFromFile(const std::string &filename, EntityList &(crv.exact.deg), &(crv.surfA.v), &(crv.surfB.v)) != 5) { - oops(); + ssassert(false, "Unexpected Curve format"); } crv.isExact = (isExact != 0); } else if(StrStartsWith(line, "CCtrl ")) { @@ -625,7 +625,7 @@ bool SolveSpaceUI::LoadEntitiesFromFile(const std::string &filename, EntityList if(sscanf(line, "CCtrl %d %lf %lf %lf Weight %lf", &i, &(c.x), &(c.y), &(c.z), &w) != 5) { - oops(); + ssassert(false, "Unexpected CCtrl format"); } crv.exact.ctrl[i] = c; crv.exact.weight[i] = w; @@ -636,16 +636,14 @@ bool SolveSpaceUI::LoadEntitiesFromFile(const std::string &filename, EntityList &vertex, &(scpt.p.x), &(scpt.p.y), &(scpt.p.z)) != 4) { - oops(); + ssassert(false, "Unexpected CurvePt format"); } scpt.vertex = (vertex != 0); crv.pts.Add(&scpt); } else if(strcmp(line, "AddCurve")==0) { sh->curve.Add(&crv); crv = {}; - } else { - oops(); - } + } else ssassert(false, "Unexpected operation"); } fclose(fh); @@ -733,7 +731,7 @@ static std::string MakePathAbsolute(const std::string &base, const std::string & if(part == ".") { /* do nothing */ } else if(part == "..") { - if(resultParts.empty()) oops(); + ssassert(!resultParts.empty(), "Relative path pointing outside of root directory"); resultParts.pop_back(); } else { resultParts.push_back(part); diff --git a/src/generate.cpp b/src/generate.cpp index 0931d7d..c96217c 100644 --- a/src/generate.cpp +++ b/src/generate.cpp @@ -101,7 +101,7 @@ bool SolveSpaceUI::PruneRequests(hGroup hg) { if(EntityExists(e->workplane)) continue; - if(!e->h.isFromRequest()) oops(); + ssassert(e->h.isFromRequest(), "Only explicitly created entities can be pruned"); (deleted.requests)++; SK.request.RemoveById(e->h.request()); @@ -199,7 +199,7 @@ void SolveSpaceUI::GenerateAll(GenerateType type, bool andFindFree, bool genForB break; } - default: oops(); + default: ssassert(false, "Unexpected generation mode"); } // If we're generating entities for display, first we need to find diff --git a/src/glhelper.cpp b/src/glhelper.cpp index e08aa07..9aacc3a 100644 --- a/src/glhelper.cpp +++ b/src/glhelper.cpp @@ -127,7 +127,7 @@ void ssglStippledLine(Vector a, Vector b, double width, case Style::STIPPLE_DOT: stipplePattern = "."; break; case Style::STIPPLE_FREEHAND: stipplePattern = "~"; break; case Style::STIPPLE_ZIGZAG: stipplePattern = "~__"; break; - default: oops(); + default: ssassert(false, "Unexpected stipple pattern"); } ssglStippledLine(a, b, width, stipplePattern, stippleScale, maybeFat); } @@ -135,7 +135,7 @@ void ssglStippledLine(Vector a, Vector b, double width, void ssglStippledLine(Vector a, Vector b, double width, const char *stipplePattern, double stippleScale, bool maybeFat) { - if(stipplePattern == NULL || *stipplePattern == 0) oops(); + ssassert(stipplePattern != NULL, "Unexpected stipple pattern"); Vector dir = b.Minus(a); double len = dir.Magnitude(); @@ -202,7 +202,7 @@ void ssglStippledLine(Vector a, Vector b, double width, break; } - default: oops(); + default: ssassert(false, "Unexpected stipple pattern element"); } if(*(++si) == 0) si = stipplePattern; } while(end > 0.0); diff --git a/src/graphicswin.cpp b/src/graphicswin.cpp index 61fb4de..8776f29 100644 --- a/src/graphicswin.cpp +++ b/src/graphicswin.cpp @@ -596,7 +596,7 @@ void GraphicsWindow::MenuView(int id) { SS.GW.EnsureValidActives(); break; - default: oops(); + default: ssassert(false, "Unexpected menu ID"); } InvalidateGraphics(); } @@ -938,7 +938,7 @@ void GraphicsWindow::MenuEdit(int id) { SS.ScheduleShowTW(); break; - default: oops(); + default: ssassert(false, "Unexpected menu ID"); } } @@ -1035,7 +1035,7 @@ c: SS.GW.SplitLinesOrCurves(); break; - default: oops(); + default: ssassert(false, "Unexpected menu ID"); } } diff --git a/src/group.cpp b/src/group.cpp index 845cfff..2b921e5 100644 --- a/src/group.cpp +++ b/src/group.cpp @@ -241,7 +241,7 @@ void Group::MenuGroup(int id) { break; } - default: oops(); + default: ssassert(false, "Unexpected menu ID"); } // Copy color from the previous mesh-contributing group. @@ -287,7 +287,7 @@ void Group::MenuGroup(int id) { } void Group::TransformImportedBy(Vector t, Quaternion q) { - if(type != LINKED) oops(); + ssassert(type == LINKED, "Expected a linked group"); hParam tx, ty, tz, qw, qx, qy, qz; tx = h.param(0); @@ -362,7 +362,7 @@ void Group::Generate(IdList *entity, } else if(subtype == WORKPLANE_BY_POINT_ORTHO) { // Already given, numerically. q = predef.q; - } else oops(); + } else ssassert(false, "Unexpected workplane subtype"); Entity normal = {}; normal.type = Entity::NORMAL_N_COPY; @@ -398,7 +398,7 @@ void Group::Generate(IdList *entity, ai = 0; af = 2; } else if(subtype == TWO_SIDED) { ai = -1; af = 1; - } else oops(); + } else ssassert(false, "Unexpected extrusion subtype"); // Get some arbitrary point in the sketch, that will be used // as a reference when defining top and bottom faces. @@ -549,7 +549,7 @@ void Group::Generate(IdList *entity, } break; - default: oops(); + default: ssassert(false, "Unexpected group type"); } } diff --git a/src/importdxf.cpp b/src/importdxf.cpp index a8b721d..2a698d0 100644 --- a/src/importdxf.cpp +++ b/src/importdxf.cpp @@ -685,7 +685,7 @@ public: if(addPendingBlockEntity(data)) return; auto bi = blocks.find(data.name); - if(bi == blocks.end()) oops(); + ssassert(bi != blocks.end(), "Inserted block does not exist"); Block *block = &bi->second; // Push transform. diff --git a/src/lib.cpp b/src/lib.cpp index d87a4f0..d89370c 100644 --- a/src/lib.cpp +++ b/src/lib.cpp @@ -229,7 +229,7 @@ default: dbp("bad constraint type %d", sc->type); return; ssys->result = SLVS_RESULT_TOO_MANY_UNKNOWNS; break; - default: oops(); + default: ssassert(false, "Unexpected solver result"); } // Write the new parameter values back to our caller. diff --git a/src/mesh.cpp b/src/mesh.cpp index 4fec2b4..737a92e 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -1014,7 +1014,7 @@ void SKdNode::MakeCertainEdgesInto(SEdgeList *sel, int how, bool coplanarIsInter } break; - default: oops(); + default: ssassert(false, "Unexpected edge class"); } cnt++; diff --git a/src/modify.cpp b/src/modify.cpp index 47eee36..1d18fa0 100644 --- a/src/modify.cpp +++ b/src/modify.cpp @@ -131,9 +131,7 @@ void GraphicsWindow::ParametricCurve::MakeFromEntity(hEntity he, bool reverse) { EntityBase *wrkpln = SK.GetEntity(e->workplane)->Normal(); u = wrkpln->NormalU(); v = wrkpln->NormalV(); - } else { - oops(); - } + } else ssassert(false, "Unexpected entity type"); } double GraphicsWindow::ParametricCurve::LengthForAuto(void) { if(isLine) { @@ -518,7 +516,7 @@ hEntity GraphicsWindow::SplitCubic(hEntity he, Vector pinter) { int i, j; for(i = 0; i < sbl.l.n; i++) { SBezier *sb = &(sbl.l.elem[i]); - if(sb->deg != 3) oops(); + ssassert(sb->deg == 3, "Expected a cubic bezier"); sb->ClosestPointTo(pinter, &t, false); if(pinter.Equals(sb->PointAt(t))) { diff --git a/src/mouse.cpp b/src/mouse.cpp index a77e1e0..4da6218 100644 --- a/src/mouse.cpp +++ b/src/mouse.cpp @@ -455,7 +455,7 @@ void GraphicsWindow::MouseMoved(double x, double y, bool leftDown, InvalidateGraphics(); break; - default: oops(); + default: ssassert(false, "Unexpected pending operation"); } if(pending.operation != 0 && @@ -590,7 +590,7 @@ void GraphicsWindow::MouseRightUp(double x, double y) { Entity *e = SK.GetEntity(gs.entity[0]); e->GetDistance(Point2d::From(x, y)); addAfterPoint = e->dogd.data; - if(addAfterPoint == -1) oops(); + ssassert(addAfterPoint != -1, "Expected a nearest bezier point to be located"); // Skip derivative point. if(r->type == Request::CUBIC) addAfterPoint++; AddContextMenuItem("Add Spline Point", CMNU_ADD_SPLINE_PT); @@ -708,7 +708,7 @@ void GraphicsWindow::MouseRightUp(double x, double y) { Request *r = SK.GetRequest(hr); int index = r->IndexOfPoint(gs.point[0]); - if(r->extraPoints == 0) oops(); + ssassert(r->extraPoints != 0, "Expected a bezier with interior control points"); SS.UndoRemember(); Entity *e = SK.GetEntity(r->h.entity(0)); diff --git a/src/platform/cocoamain.mm b/src/platform/cocoamain.mm index 7fd2a6e..069923b 100644 --- a/src/platform/cocoamain.mm +++ b/src/platform/cocoamain.mm @@ -409,7 +409,7 @@ CONVERT(Rect) - (void)prepareEditorWithMinWidthInChars:(int)minWidthChars { NSFont *font = [editor font]; NSGlyph glyphA = [font glyphWithName:@"a"]; - if(glyphA == -1) oops(); + ssassert(glyphA != -1, "Expected font to have U+0061"); CGFloat glyphAWidth = [font advancementForGlyph:glyphA].width; [editor sizeToFit]; @@ -578,7 +578,7 @@ void AddContextMenuItem(const char *label, int id_) { } void CreateContextSubmenu(void) { - if(contextSubmenu) oops(); + ssassert(!contextSubmenu, "Unexpected nested submenu"); contextSubmenu = [[NSMenu alloc] initWithTitle:@""]; } @@ -637,8 +637,8 @@ void InitMainMenu(NSMenu *mainMenu) { [menu setAutoenablesItems:NO]; [menuItem setSubmenu:menu]; - if(entry->level >= sizeof(levels) / sizeof(levels[0])) - oops(); + ssassert((unsigned)entry->level < sizeof(levels) / sizeof(levels[0]), + "Unexpected depth of menu nesting"); levels[entry->level] = menu; } @@ -1145,7 +1145,7 @@ const void *SolveSpace::LoadResource(const std::string &name, size_t *size) { if(data == nil) { NSString *path = [[NSBundle mainBundle] pathForResource:key ofType:nil]; data = [[NSFileHandle fileHandleForReadingAtPath:path] readDataToEndOfFile]; - if(data == nil) oops(); + ssassert(data != nil, "Cannot find resource"); [cache setObject:data forKey:key]; } diff --git a/src/platform/gloffscreen.cpp b/src/platform/gloffscreen.cpp index be836e2..84ee0e2 100644 --- a/src/platform/gloffscreen.cpp +++ b/src/platform/gloffscreen.cpp @@ -14,12 +14,10 @@ GLOffscreen::GLOffscreen() : _pixels(NULL), _pixels_inv(NULL), _width(0), _height(0) { #ifndef __APPLE__ - if(glewInit() != GLEW_OK) - oops(); + ssassert(glewInit() == GLEW_OK, "Unexpected GLEW failure"); #endif - if(!GL_EXT_framebuffer_object) - oops(); + ssassert(GL_EXT_framebuffer_object, "Expected an available FBO extension"); glGenFramebuffersEXT(1, &_framebuffer); glGenRenderbuffersEXT(1, &_color_renderbuffer); diff --git a/src/platform/gtkmain.cpp b/src/platform/gtkmain.cpp index 077ee7f..90a47a7 100644 --- a/src/platform/gtkmain.cpp +++ b/src/platform/gtkmain.cpp @@ -243,15 +243,11 @@ public: _xdisplay = gdk_x11_get_default_xdisplay(); int glxmajor, glxminor; - if(!glXQueryVersion(_xdisplay, &glxmajor, &glxminor)) { - dbp("OpenGL is not supported"); - oops(); - } + ssassert(glXQueryVersion(_xdisplay, &glxmajor, &glxminor), + "Expected OpenGL to be available"); - if(glxmajor < 1 || (glxmajor == 1 && glxminor < 3)) { - dbp("GLX version %d.%d is too old; 1.3 required", glxmajor, glxminor); - oops(); - } + ssassert(glxmajor > 1 || (glxmajor == 1 && glxminor >= 3), + "Expected GLX >= 1.3"); static int fbconfig_attrs[] = { GLX_RENDER_TYPE, GLX_RGBA_BIT, @@ -264,8 +260,8 @@ public: int fbconfig_num = 0; GLXFBConfig *fbconfigs = glXChooseFBConfig(_xdisplay, DefaultScreen(_xdisplay), fbconfig_attrs, &fbconfig_num); - if(!fbconfigs || fbconfig_num == 0) - oops(); + ssassert(fbconfigs && fbconfig_num > 0, + "Expected an available framebuffer configuration"); /* prefer FBConfigs with depth of 32; * Mesa software rasterizer explodes with a BadMatch without this; @@ -291,10 +287,7 @@ public: _glcontext = glXCreateNewContext(_xdisplay, fbconfig, GLX_RGBA_TYPE, 0, True); - if(!_glcontext) { - dbp("cannot create OpenGL context"); - oops(); - } + ssassert(_glcontext != NULL, "Cannot create an OpenGL context"); XFree(fbconfigs); @@ -329,15 +322,15 @@ protected: bool on_expose_event(GdkEventExpose *) override { const Cairo::RefPtr &cr = get_window()->create_cairo_context(); #endif - if(!glXMakeCurrent(_xdisplay, _xwindow, _glcontext)) - oops(); + ssassert(glXMakeCurrent(_xdisplay, _xwindow, _glcontext), + "Cannot make OpenGL context current"); if(!_offscreen) _offscreen = new GLOffscreen; Gdk::Rectangle allocation = get_allocation(); - if(!_offscreen->begin(allocation.get_width(), allocation.get_height())) - oops(); + ssassert(_offscreen->begin(allocation.get_width(), allocation.get_height()), + "Cannot allocate offscreen rendering buffer"); on_gl_draw(); glFlush(); @@ -860,7 +853,7 @@ void AddContextMenuItem(const char *label, int id) { } void CreateContextSubmenu(void) { - if(context_submenu) oops(); + ssassert(!context_submenu, "Unexpected nested submenu"); context_submenu = new Gtk::Menu; } @@ -969,8 +962,8 @@ static void InitMainMenu(Gtk::MenuShell *menu_shell) { Gtk::Menu *menu = new Gtk::Menu; menu_item->set_submenu(*menu); - if((unsigned)entry->level >= sizeof(levels) / sizeof(levels[0])) - oops(); + ssassert((unsigned)entry->level < sizeof(levels) / sizeof(levels[0]), + "Unexpected depth of menu nesting"); levels[entry->level] = menu; } @@ -1144,8 +1137,7 @@ static void ChooserFilterChanged(Gtk::FileChooserDialog *chooser) int rdelim = filter_name.find(',', lparen); if(rdelim < 0) rdelim = filter_name.find(')', lparen); - if(lparen < 0 || rdelim < 0) - oops(); + ssassert(lparen > 0 && rdelim > 0, "Expected to find a parenthesized extension"); std::string extension = filter_name.substr(lparen, rdelim - lparen); if(extension == "*") @@ -1506,14 +1498,14 @@ const void *LoadResource(const std::string &name, size_t *size) { path = (UNIX_DATADIR "/") + name; if(stat(path.c_str(), &st)) { - if(errno != ENOENT) oops(); + ssassert(errno == ENOENT, "Unexpected stat() error"); path = resource_dir + "/" + name; - if(stat(path.c_str(), &st)) oops(); + ssassert(!stat(path.c_str(), &st), "Cannot find resource"); } std::vector data(st.st_size); FILE *f = ssfopen(path.c_str(), "rb"); - if(!f) oops(); + ssassert(f != NULL, "Cannot open resource"); fread(&data[0], 1, st.st_size, f); fclose(f); diff --git a/src/platform/unixutil.cpp b/src/platform/unixutil.cpp index ef1a86a..31366dd 100644 --- a/src/platform/unixutil.cpp +++ b/src/platform/unixutil.cpp @@ -51,13 +51,15 @@ void assert_failure(const char *file, unsigned line, const char *function, FILE *ssfopen(const std::string &filename, const char *mode) { - if(filename.length() != strlen(filename.c_str())) oops(); + ssassert(filename.length() == strlen(filename.c_str()), + "Unexpected null byte in middle of a path"); return fopen(filename.c_str(), mode); } void ssremove(const std::string &filename) { - if(filename.length() != strlen(filename.c_str())) oops(); + ssassert(filename.length() == strlen(filename.c_str()), + "Unexpected null byte in middle of a path"); remove(filename.c_str()); } @@ -114,7 +116,7 @@ void FreeAllTemporary(void) void *MemAlloc(size_t n) { void *p = malloc(n); - if(!p) oops(); + ssassert(p != NULL, "Cannot allocate memory"); return p; } diff --git a/src/platform/w32main.cpp b/src/platform/w32main.cpp index 72b3316..a3fe02b 100644 --- a/src/platform/w32main.cpp +++ b/src/platform/w32main.cpp @@ -744,9 +744,9 @@ static void CreateGlContext(HWND hwnd, HGLRC *glrc) pfd.cStencilBits = 0; pixelFormat = ChoosePixelFormat(hdc, &pfd); - if(!pixelFormat) oops(); + ssassert(pixelFormat != 0, "Expected a valid pixel format to be chosen"); - if(!SetPixelFormat(hdc, pixelFormat, &pfd)) oops(); + ssassert(SetPixelFormat(hdc, pixelFormat, &pfd), "Cannot set pixel format"); *glrc = wglCreateContext(hdc); wglMakeCurrent(hdc, *glrc); @@ -928,8 +928,6 @@ LRESULT CALLBACK GraphicsWndProc(HWND hwnd, UINT msg, WPARAM wParam, !!(wParam & MK_RBUTTON), !!(wParam & MK_SHIFT), !!(wParam & MK_CONTROL)); - } else { - oops(); } break; } @@ -955,7 +953,7 @@ LRESULT CALLBACK GraphicsWndProc(HWND hwnd, UINT msg, WPARAM wParam, break; } } - if(SS.GW.menu[i].level < 0) oops(); + ssassert(SS.GW.menu[i].level >= 0, "Cannot find command in the menu"); } break; } @@ -1153,8 +1151,8 @@ static void MenuById(int id, bool yes, bool check) if(SS.GW.menu[i].level == 0) subMenu++; if(SS.GW.menu[i].id == id) { - if(subMenu < 0) oops(); - if(subMenu >= (int)arraylen(SubMenus)) oops(); + ssassert(subMenu >= 0 && subMenu < (int)arraylen(SubMenus), + "Submenu out of range"); if(check) { CheckMenuItem(SubMenus[subMenu], id, @@ -1166,7 +1164,7 @@ static void MenuById(int id, bool yes, bool check) return; } } - oops(); + ssassert(false, "Cannot find submenu"); } void SolveSpace::CheckMenuById(int id, bool checked) { @@ -1219,7 +1217,7 @@ HMENU CreateGraphicsWindowMenus(void) if(SS.GW.menu[i].level == 0) { m = CreateMenu(); AppendMenuW(top, MF_STRING | MF_POPUP, (UINT_PTR)m, Widen(label).c_str()); - if(subMenu >= (int)arraylen(SubMenus)) oops(); + ssassert(subMenu < (int)arraylen(SubMenus), "Too many submenus"); SubMenus[subMenu] = m; subMenu++; } else if(SS.GW.menu[i].level == 1) { @@ -1236,7 +1234,7 @@ HMENU CreateGraphicsWindowMenus(void) } else { AppendMenuW(m, MF_SEPARATOR, SS.GW.menu[i].id, L""); } - } else oops(); + } else ssassert(false, "Submenus nested too deeply"); } RefreshRecentMenus(); @@ -1261,7 +1259,7 @@ static void CreateMainWindows(void) IMAGE_ICON, 32, 32, 0); wc.hIconSm = (HICON)LoadImage(Instance, MAKEINTRESOURCE(4000), IMAGE_ICON, 16, 16, 0); - if(!RegisterClassEx(&wc)) oops(); + ssassert(RegisterClassEx(&wc), "Cannot register window class"); HMENU top = CreateGraphicsWindowMenus(); GraphicsWnd = CreateWindowExW(0, L"GraphicsWnd", @@ -1269,7 +1267,7 @@ static void CreateMainWindows(void) WS_OVERLAPPED | WS_THICKFRAME | WS_CLIPCHILDREN | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SYSMENU | WS_SIZEBOX | WS_CLIPSIBLINGS, 50, 50, 900, 600, NULL, top, Instance, NULL); - if(!GraphicsWnd) oops(); + ssassert(GraphicsWnd != NULL, "Cannot create window"); GraphicsEditControl = CreateWindowExW(WS_EX_CLIENTEDGE, WC_EDIT, L"", WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS, @@ -1282,14 +1280,14 @@ static void CreateMainWindows(void) wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wc.lpszClassName = L"TextWnd"; wc.hCursor = NULL; - if(!RegisterClassEx(&wc)) oops(); + ssassert(RegisterClassEx(&wc), "Cannot register window class"); // We get the desired Alt+Tab behaviour by specifying that the text // window is a child of the graphics window. TextWnd = CreateWindowExW(0, L"TextWnd", L"SolveSpace - Property Browser", WS_THICKFRAME | WS_CLIPCHILDREN, 650, 500, 420, 300, GraphicsWnd, (HMENU)NULL, Instance, NULL); - if(!TextWnd) oops(); + ssassert(TextWnd != NULL, "Cannot create window"); TextWndScrollBar = CreateWindowExW(0, WC_SCROLLBAR, L"", WS_CHILD | SBS_VERT | SBS_LEFTALIGN | WS_VISIBLE | WS_CLIPSIBLINGS, @@ -1313,9 +1311,9 @@ static void CreateMainWindows(void) const void *SolveSpace::LoadResource(const std::string &name, size_t *size) { HRSRC hres = FindResourceW(NULL, Widen(name).c_str(), RT_RCDATA); - if(!hres) oops(); + ssassert(hres != NULL, "Cannot find resource"); HGLOBAL res = LoadResource(NULL, hres); - if(!res) oops(); + ssassert(res != NULL, "Cannot load resource"); *size = SizeofResource(NULL, hres); return LockResource(res); diff --git a/src/platform/w32util.cpp b/src/platform/w32util.cpp index 588e04d..b9d72a8 100644 --- a/src/platform/w32util.cpp +++ b/src/platform/w32util.cpp @@ -40,8 +40,8 @@ std::string Narrow(const wchar_t *in) std::string out; DWORD len = WideCharToMultiByte(CP_UTF8, 0, in, -1, NULL, 0, NULL, NULL); out.resize(len - 1); - if(!WideCharToMultiByte(CP_UTF8, 0, in, -1, &out[0], len, NULL, NULL)) - oops(); + ssassert(WideCharToMultiByte(CP_UTF8, 0, in, -1, &out[0], len, NULL, NULL), + "Invalid UTF-16"); return out; } @@ -51,9 +51,9 @@ std::string Narrow(const std::wstring &in) std::string out; out.resize(WideCharToMultiByte(CP_UTF8, 0, &in[0], in.length(), NULL, 0, NULL, NULL)); - if(!WideCharToMultiByte(CP_UTF8, 0, &in[0], in.length(), - &out[0], out.length(), NULL, NULL)) - oops(); + ssassert(WideCharToMultiByte(CP_UTF8, 0, &in[0], in.length(), + &out[0], out.length(), NULL, NULL), + "Invalid UTF-16"); return out; } @@ -62,8 +62,8 @@ std::wstring Widen(const char *in) std::wstring out; DWORD len = MultiByteToWideChar(CP_UTF8, 0, in, -1, NULL, 0); out.resize(len - 1); - if(!MultiByteToWideChar(CP_UTF8, 0, in, -1, &out[0], len)) - oops(); + ssassert(MultiByteToWideChar(CP_UTF8, 0, in, -1, &out[0], len), + "Invalid UTF-8"); return out; } @@ -73,8 +73,8 @@ std::wstring Widen(const std::string &in) std::wstring out; out.resize(MultiByteToWideChar(CP_UTF8, 0, &in[0], in.length(), NULL, 0)); - if(!MultiByteToWideChar(CP_UTF8, 0, &in[0], in.length(), &out[0], out.length())) - oops(); + ssassert(MultiByteToWideChar(CP_UTF8, 0, &in[0], in.length(), &out[0], out.length()), + "Invalid UTF-8"); return out; } @@ -88,13 +88,15 @@ FILE *ssfopen(const std::string &filename, const char *mode) if(uncFilename.substr(0, 2) != "\\\\") uncFilename = "\\\\?\\" + uncFilename; - if(filename.length() != strlen(filename.c_str())) oops(); + ssassert(filename.length() == strlen(filename.c_str()), + "Unexpected null byte in middle of a path"); return _wfopen(Widen(uncFilename).c_str(), Widen(mode).c_str()); } void ssremove(const std::string &filename) { - if(filename.length() != strlen(filename.c_str())) oops(); + ssassert(filename.length() == strlen(filename.c_str()), + "Unexpected null byte in middle of a path"); _wremove(Widen(filename).c_str()); } @@ -107,7 +109,7 @@ void ssremove(const std::string &filename) void *AllocTemporary(size_t n) { void *v = HeapAlloc(TempHeap, HEAP_NO_SERIALIZE | HEAP_ZERO_MEMORY, n); - if(!v) oops(); + ssassert(v != NULL, "Cannot allocate memory"); return v; } void FreeTemporary(void *p) { @@ -124,7 +126,7 @@ void FreeAllTemporary(void) void *MemAlloc(size_t n) { void *p = HeapAlloc(PermHeap, HEAP_NO_SERIALIZE | HEAP_ZERO_MEMORY, n); - if(!p) oops(); + ssassert(p != NULL, "Cannot allocate memory"); return p; } void MemFree(void *p) { @@ -132,8 +134,8 @@ void MemFree(void *p) { } void vl(void) { - if(!HeapValidate(TempHeap, HEAP_NO_SERIALIZE, NULL)) oops(); - if(!HeapValidate(PermHeap, HEAP_NO_SERIALIZE, NULL)) oops(); + ssassert(HeapValidate(TempHeap, HEAP_NO_SERIALIZE, NULL), "Corrupted heap"); + ssassert(HeapValidate(PermHeap, HEAP_NO_SERIALIZE, NULL), "Corrupted heap"); } void InitHeaps(void) { diff --git a/src/polygon.cpp b/src/polygon.cpp index eae40fe..bc1f322 100644 --- a/src/polygon.cpp +++ b/src/polygon.cpp @@ -545,7 +545,7 @@ Vector SContour::ComputeNormal(void) { } Vector SContour::AnyEdgeMidpoint(void) { - if(l.n < 2) oops(); + ssassert(l.n >= 2, "Need two points to find a midpoint"); return ((l.elem[0].p).Plus(l.elem[1].p)).ScaledBy(0.5); } @@ -696,7 +696,7 @@ bool SPolygon::IsEmpty(void) { } Vector SPolygon::AnyPoint(void) { - if(IsEmpty()) oops(); + ssassert(!IsEmpty(), "Need at least one point"); return l.elem[0].l.elem[0].p; } diff --git a/src/request.cpp b/src/request.cpp index b770e06..03db380 100644 --- a/src/request.cpp +++ b/src/request.cpp @@ -147,7 +147,7 @@ void Request::Generate(IdList *entity, // and this is just a copy of the workplane quaternion, // so no params required } - if(points < 1) oops(); + ssassert(points >= 1, "Positioning a normal requires a point"); // The point determines where the normal gets displayed on-screen; // it's entirely cosmetic. n.point[0] = e.point[0]; diff --git a/src/resource.cpp b/src/resource.cpp index 808a7d5..5f590c1 100644 --- a/src/resource.cpp +++ b/src/resource.cpp @@ -17,36 +17,31 @@ namespace SolveSpace { std::string LoadString(const std::string &name) { size_t size; const void *data = LoadResource(name, &size); - if(data == NULL) oops(); - return std::string(static_cast(data), size); } std::string LoadStringFromGzip(const std::string &name) { size_t size; const void *data = LoadResource(name, &size); - if(data == NULL) oops(); z_stream stream; stream.zalloc = Z_NULL; stream.zfree = Z_NULL; stream.opaque = Z_NULL; - if(inflateInit2(&stream, /*decode gzip header*/16) != Z_OK) - oops(); + ssassert(inflateInit2(&stream, /*decode gzip header*/16) == Z_OK, + "Cannot start inflation"); // Extract length mod 2**32 from the gzip trailer. std::string result; - if(size < 4) oops(); + ssassert(size >= 4, "Resource too small to have gzip trailer"); result.resize(*(uint32_t *)((uintptr_t)data + size - 4)); stream.next_in = (Bytef *)data; stream.avail_in = size; stream.next_out = (Bytef *)&result[0]; stream.avail_out = result.length(); - if(inflate(&stream, Z_NO_FLUSH) != Z_STREAM_END) - oops(); - if(stream.avail_out != 0) - oops(); + ssassert(inflate(&stream, Z_NO_FLUSH) == Z_STREAM_END, "Cannot inflate resource"); + ssassert(stream.avail_out == 0, "Inflated resource larger than what trailer indicates"); inflateEnd(&stream); @@ -56,10 +51,9 @@ std::string LoadStringFromGzip(const std::string &name) { Pixmap LoadPNG(const std::string &name) { size_t size; const void *data = LoadResource(name, &size); - if(data == NULL) oops(); Pixmap pixmap = Pixmap::FromPNG(static_cast(data), size); - if(pixmap.IsEmpty()) oops(); + ssassert(!pixmap.IsEmpty(), "Cannot load pixmap"); return pixmap; } @@ -189,12 +183,12 @@ public: } char ReadChar() { - if(AtEnd()) oops(); + ssassert(!AtEnd(), "Unexpected EOF"); return *pos++; } bool TryChar(char c) { - if(AtEnd()) oops(); + ssassert(!AtEnd(), "Unexpected EOF"); if(*pos == c) { pos++; return true; @@ -204,7 +198,7 @@ public: } void ExpectChar(char c) { - if(ReadChar() != c) oops(); + ssassert(ReadChar() == c, "Unexpected character"); } uint8_t Read4HexBits() { @@ -215,7 +209,7 @@ public: return 10 + (c - 'a'); } else if(c >= 'A' && c <= 'F') { return 10 + (c - 'A'); - } else oops(); + } else ssassert(false, "Unexpected hex digit"); } uint8_t Read8HexBits() { @@ -233,12 +227,12 @@ public: double ReadDoubleString() { char *endptr; double d = strtod(&*pos, &endptr); - if(&*pos == endptr) oops(); + ssassert(&*pos != endptr, "Cannot read a double-precision number"); pos += endptr - &*pos; return d; } - bool ReadRegex(const std::regex &re, std::smatch *m) { + bool TryRegex(const std::regex &re, std::smatch *m) { if(std::regex_search(pos, end, *m, re, std::regex_constants::match_continuous)) { pos = (*m)[0].second; return true; @@ -269,9 +263,12 @@ BitmapFont BitmapFont::From(std::string &&unifontData) { } void BitmapFont::AddGlyph(char32_t codepoint, const Pixmap &pixmap) { - if(pixmap.width != 8 && pixmap.width != 16 && pixmap.height != 16) oops(); - if(glyphs.find(codepoint) != glyphs.end()) oops(); - if(nextPosition == 0xffff) oops(); + ssassert((pixmap.width == 8 || pixmap.width == 16) && pixmap.height == 16, + "Unexpected glyph dimensions"); + ssassert(glyphs.find(codepoint) == glyphs.end(), + "Glyph with this codepoint already exists"); + ssassert(nextPosition != 0xffff, + "Too many glyphs for current texture size"); BitmapFont::Glyph glyph = {}; glyph.advanceCells = pixmap.width / 8; @@ -294,7 +291,8 @@ const BitmapFont::Glyph &BitmapFont::GetGlyph(char32_t codepoint) { return (*it).second; } - if(nextPosition == 0xffff) oops(); + ssassert(nextPosition != 0xffff, + "Too many glyphs for current texture size"); // Find the hex representation in the (sorted) Unifont file. auto first = unifontData.cbegin(), @@ -344,7 +342,7 @@ const BitmapFont::Glyph &BitmapFont::GetGlyph(char32_t codepoint) { for(size_t i = 0; i < 16; i++) { glyphBits[i] = (uint16_t)reader.Read8HexBits() << 8; } - } else oops(); + } else ssassert(false, "Unexpected glyph bitmap length"); // Fill in the texture (one texture byte per glyph bit). for(size_t y = 0; y < 16; y++) { @@ -361,7 +359,7 @@ const BitmapFont::Glyph &BitmapFont::GetGlyph(char32_t codepoint) { } // Glyph doesn't exist; return replacement glyph instead. - if(codepoint == 0xfffd) oops(); + ssassert(codepoint != 0xfffd, "Cannot parse replacement glyph"); return GetGlyph(0xfffd); } @@ -461,7 +459,7 @@ VectorFont VectorFont::From(std::string &&lffData) { ASCIIReader reader = ASCIIReader::From(font.lffData); std::smatch m; - while(reader.ReadRegex(std::regex("#\\s*(\\w+)\\s*:\\s*(.+?)\n"), &m)) { + while(reader.TryRegex(std::regex("#\\s*(\\w+)\\s*:\\s*(.+?)\n"), &m)) { std::string name = m.str(1), value = m.str(2); std::transform(name.begin(), name.end(), name.begin(), ::tolower); @@ -488,7 +486,7 @@ const VectorFont::Glyph &VectorFont::GetGlyph(char32_t codepoint) { } auto firstGlyph = std::find(lffData.cbegin(), lffData.cend(), '['); - if(firstGlyph == lffData.cend()) oops(); + ssassert(firstGlyph != lffData.cend(), "Vector font contains no glyphs"); // Find the serialized representation in the (sorted) lff file. auto first = firstGlyph, @@ -572,7 +570,7 @@ const VectorFont::Glyph &VectorFont::GetGlyph(char32_t codepoint) { } // Glyph doesn't exist; return replacement glyph instead. - if(codepoint == 0xfffd) oops(); + ssassert(codepoint != 0xfffd, "Cannot parse replacement glyph"); return GetGlyph(0xfffd); } diff --git a/src/sketch.h b/src/sketch.h index 26625fe..18189ba 100644 --- a/src/sketch.h +++ b/src/sketch.h @@ -881,7 +881,7 @@ inline hRequest hEntity::request(void) inline hGroup hEntity::group(void) { hGroup r; r.v = (v >> 16) & 0x3fff; return r; } inline hEquation hEntity::equation(int i) - { if(i != 0) oops(); hEquation r; r.v = v | 0x40000000; return r; } + { hEquation r; r.v = v | 0x40000000; return r; } inline hRequest hParam::request(void) { hRequest r; r.v = (v >> 16); return r; } diff --git a/src/solvespace.cpp b/src/solvespace.cpp index a13107c..b845c89 100644 --- a/src/solvespace.cpp +++ b/src/solvespace.cpp @@ -426,7 +426,7 @@ bool SolveSpaceUI::OkayToStartNewFile(void) { case DIALOG_CANCEL: return false; - default: oops(); break; + default: ssassert(false, "Unexpected dialog choice"); } } @@ -557,7 +557,7 @@ void SolveSpaceUI::MenuFile(int id) { ImportDxf(importFile); } else if(Extension(importFile) == "dwg") { ImportDwg(importFile); - } else oops(); + } else ssassert(false, "Unexpected extension of file to import"); SS.GenerateAll(SolveSpaceUI::GENERATE_UNTIL_ACTIVE); SS.ScheduleShowTW(); @@ -569,7 +569,7 @@ void SolveSpaceUI::MenuFile(int id) { SS.Exit(); break; - default: oops(); + default: ssassert(false, "Unexpected menu ID"); } SS.UpdateWindowTitle(); @@ -796,7 +796,7 @@ void SolveSpaceUI::MenuAnalyze(int id) { break; } - default: oops(); + default: ssassert(false, "Unexpected menu ID"); } } @@ -823,7 +823,7 @@ void SolveSpaceUI::MenuHelp(int id) { ); break; - default: oops(); + default: ssassert(false, "Unexpected menu ID"); } } diff --git a/src/solvespace.h b/src/solvespace.h index 40fe7cf..cd77821 100644 --- a/src/solvespace.h +++ b/src/solvespace.h @@ -74,8 +74,6 @@ struct FT_FaceRec_; } while(0) #endif -#define oops() ssassert(false, "oops() called") - #ifndef isnan # define isnan(x) (((x) != (x)) || (x > 1e11) || (x < -1e11)) #endif diff --git a/src/srf/boolean.cpp b/src/srf/boolean.cpp index d064952..54aee88 100644 --- a/src/srf/boolean.cpp +++ b/src/srf/boolean.cpp @@ -43,7 +43,7 @@ SCurve SCurve::MakeCopySplitAgainst(SShell *agnstA, SShell *agnstB, ret.pts = {}; SCurvePt *p = pts.First(); - if(!p) oops(); + ssassert(p != NULL, "Cannot split an empty curve"); SCurvePt prev = *p; ret.pts.Add(p); p = pts.NextAfter(p); @@ -221,7 +221,7 @@ static bool KeepRegion(int type, bool opA, int shell, int orig) return (inShell && !inFace) || inSame; } - default: oops(); + default: ssassert(false, "Unexpected shell type"); } } static bool KeepEdge(int type, bool opA, @@ -295,7 +295,7 @@ static void DEBUGEDGELIST(SEdgeList *sel, SSurface *surf) { void SSurface::FindChainAvoiding(SEdgeList *src, SEdgeList *dest, SPointList *avoid) { - if(src->l.n < 1) oops(); + ssassert(src->l.n > 0, "Need at least one edge"); // Start with an arbitrary edge. dest->l.Add(&(src->l.elem[0])); src->l.ClearTags(); diff --git a/src/srf/curve.cpp b/src/srf/curve.cpp index ba54afc..4adede3 100644 --- a/src/srf/curve.cpp +++ b/src/srf/curve.cpp @@ -764,7 +764,7 @@ SSurface *SCurve::GetSurfaceA(SShell *a, SShell *b) { return b->surface.FindById(surfA); } else if(source == FROM_INTERSECTION) { return a->surface.FindById(surfA); - } else oops(); + } else ssassert(false, "Unexpected curve source"); } SSurface *SCurve::GetSurfaceB(SShell *a, SShell *b) { @@ -774,7 +774,7 @@ SSurface *SCurve::GetSurfaceB(SShell *a, SShell *b) { return b->surface.FindById(surfB); } else if(source == FROM_INTERSECTION) { return b->surface.FindById(surfB); - } else oops(); + } else ssassert(false, "Unexpected curve source"); } //----------------------------------------------------------------------------- diff --git a/src/srf/ratpoly.cpp b/src/srf/ratpoly.cpp index 2f6a0bb..bfbb951 100644 --- a/src/srf/ratpoly.cpp +++ b/src/srf/ratpoly.cpp @@ -51,7 +51,7 @@ double SolveSpace::Bernstein(int k, int deg, double t) } break; } - oops(); + ssassert(false, "Unexpected degree of spline"); } double SolveSpace::BernsteinDerivative(int k, int deg, double t) @@ -90,7 +90,7 @@ double SolveSpace::BernsteinDerivative(int k, int deg, double t) } break; } - oops(); + ssassert(false, "Unexpected degree of spline"); } Vector SBezier::PointAt(double t) { @@ -222,7 +222,7 @@ void SBezier::SplitAt(double t, SBezier *bef, SBezier *aft) { *aft = SBezier::From(cts, ct12_23, ct23, ct[3]); break; } - default: oops(); + default: ssassert(false, "Unexpected degree of spline"); } } @@ -308,7 +308,7 @@ void SBezier::MakePwlInitialWorker(List *l, double ta, double tb, double double d = max({ pm1.DistanceToLine(pa, dir), pm2.DistanceToLine(pa, dir), - pm3.DistanceToLine(pa, dir) + pm3.DistanceToLine(pa, dir) }); double step = 1.0/SS.GetMaxSegments(); diff --git a/src/srf/raycast.cpp b/src/srf/raycast.cpp index 808287f..7dbca01 100644 --- a/src/srf/raycast.cpp +++ b/src/srf/raycast.cpp @@ -172,7 +172,7 @@ void SSurface::SplitInHalf(bool byU, SSurface *sa, SSurface *sb) { break; } - default: oops(); + default: ssassert(false, "Unexpected degree of spline"); } sa->UnWeightControlPoints(); diff --git a/src/srf/surfinter.cpp b/src/srf/surfinter.cpp index 79d71cd..998ce4c 100644 --- a/src/srf/surfinter.cpp +++ b/src/srf/surfinter.cpp @@ -97,8 +97,8 @@ void SSurface::AddExactIntersectionCurve(SBezier *sb, SSurface *srfB, } } #endif // 0 - // Nothing should be generating zero-len edges. - if((sb->Start()).Equals(sb->Finish())) oops(); + ssassert(!(sb->Start()).Equals(sb->Finish()), + "Unexpected zero-length edge"); split.source = SCurve::FROM_INTERSECTION; into->curve.AddAndAssignId(&split); diff --git a/src/style.cpp b/src/style.cpp index 91caaea..20008ec 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -554,7 +554,7 @@ void TextWindow::ScreenChangeStyleMetric(int link, uint32_t v) { meaning = EDIT_STYLE_WIDTH; break; - default: oops(); + default: ssassert(false, "Unexpected link"); } std::string edit_value; @@ -588,9 +588,7 @@ void TextWindow::ScreenChangeStyleColor(int link, uint32_t v) { } else if(link == 'f') { em = EDIT_STYLE_FILL_COLOR; rgb = s->fillColor; - } else { - oops(); - } + } else ssassert(false, "Unexpected link"); SS.TW.ShowEditControlWithColorPicker(13, rgb); SS.TW.edit.style = hs; SS.TW.edit.meaning = em; @@ -840,7 +838,7 @@ void TextWindow::ShowStyleInfo(void) { case '_': patterns[i] += "\xEE\x80\x85"; break; case '-': patterns[i] += "\xEE\x80\x86"; break; case '~': patterns[i] += "\xEE\x80\x87"; break; - default: oops(); + default: ssassert(false, "Unexpected stipple pattern element"); } } while(*(++str)); } diff --git a/src/textscreens.cpp b/src/textscreens.cpp index e00b2bd..0f37fa8 100644 --- a/src/textscreens.cpp +++ b/src/textscreens.cpp @@ -788,10 +788,7 @@ void TextWindow::EditControlDone(const char *s) { if(EditControlDoneForConfiguration(s)) cnt++; if(EditControlDoneForPaste(s)) cnt++; if(EditControlDoneForView(s)) cnt++; - if(cnt > 1) { - // The identifiers were somehow assigned not uniquely? - oops(); - } + ssassert(cnt == 1, "Expected exactly one parameter to be edited"); break; } } diff --git a/src/textwin.cpp b/src/textwin.cpp index 0e9483a..9f26594 100644 --- a/src/textwin.cpp +++ b/src/textwin.cpp @@ -48,7 +48,7 @@ void TextWindow::MakeColorTable(const Color *in, float *out) { int i; for(i = 0; in[i].c != 0; i++) { int c = in[i].c; - if(c < 0 || c > 255) oops(); + ssassert(c >= 0 && c <= 255, "Unexpected color index"); out[c*3 + 0] = in[i].color.redF(); out[c*3 + 1] = in[i].color.greenF(); out[c*3 + 2] = in[i].color.blueF(); diff --git a/src/ttf.cpp b/src/ttf.cpp index da9d227..c1555fc 100644 --- a/src/ttf.cpp +++ b/src/ttf.cpp @@ -218,7 +218,7 @@ static const FT_Outline_Funcs outline_funcs = { void TtfFont::PlotString(const std::string &str, SBezierList *sbl, Vector origin, Vector u, Vector v) { - if(fontFace == NULL) oops(); + ssassert(fontFace != NULL, "Expected font face to be loaded"); FT_Pos dx = 0; for(char32_t chr : ReadUTF8(str)) { diff --git a/src/undoredo.cpp b/src/undoredo.cpp index 04b96ee..d21ca93 100644 --- a/src/undoredo.cpp +++ b/src/undoredo.cpp @@ -100,7 +100,7 @@ void SolveSpaceUI::PushFromCurrentOnto(UndoStack *uk) { void SolveSpaceUI::PopOntoCurrentFrom(UndoStack *uk) { int i; - if(uk->cnt <= 0) oops(); + ssassert(uk->cnt > 0, "Cannot pop from empty undo stack"); (uk->cnt)--; uk->write = WRAP(uk->write - 1, MAX_UNDO); diff --git a/src/util.cpp b/src/util.cpp index 7a4b942..6555570 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -12,7 +12,7 @@ std::string SolveSpace::ssprintf(const char *fmt, ...) va_start(va, fmt); int size = vsnprintf(NULL, 0, fmt, va); - if(size < 0) oops(); + ssassert(size >= 0, "vsnprintf could not encode string"); va_end(va); std::string result; @@ -418,7 +418,7 @@ double Vector::Element(int i) { case 0: return x; case 1: return y; case 2: return z; - default: oops(); + default: ssassert(false, "Unexpected vector element index"); } } @@ -514,7 +514,7 @@ Vector Vector::Normal(int which) { // That's the vector we return. } else if(which == 1) { n = this->Cross(n); - } else oops(); + } else ssassert(false, "Unexpected vector normal index"); n = n.WithMagnitude(1);