bugfix: Fix crash bug when using zero scale factors. Reported by Alan Cox

felipesanches-svg
Marius Kintel 2012-02-19 13:09:02 +01:00
parent 955e0f1344
commit c5703b4407
15 changed files with 143 additions and 42 deletions

View File

@ -7,6 +7,8 @@ o The size of the misc. caches can now be adjusted from Preferences
o The limit for when to disable OpenCSG can now be adjusted from Preferences
o Added Dot product operator: vec * vec
o Added Matrix multiplication operator: vec * mat, mat * mat
o Added search() function
o Dependencies are now tracked - any changes in uses/included files will be detected and cause a recompile
Bugfixes:
o use'ing an non-existing file sometimes crashed under Windows
@ -14,6 +16,9 @@ o Better font handling: Ensure a monospace font is chosen as default
o Division by zero caused hang in some cases (e.g. sin(1/0))
o Larger minkowski operations sometimes caused a crash after a CGAL assert was thrown
o Fixed crashes in shared_ptr.hpp (or similar places) due to a cache management bug
o scale() with a scale factor of zero could cause a crash
o Fixed a number of issues related to use/include
o Providing an unknown parameter on the cmd-line caused a crash
Deprecations:
o The old include syntax "<filename.scad>" without the include keyword is no

View File

@ -252,31 +252,45 @@ Response CGALEvaluator::visit(State &state, const TransformNode &node)
// objects. So we convert in to our internal 2d data format, transform it,
// tesselate it and create a new CGAL_Nef_polyhedron2 from it.. What a hack!
CGAL_Aff_transformation2 t(
node.matrix(0,0), node.matrix(0,1), node.matrix(0,3),
node.matrix(1,0), node.matrix(1,1), node.matrix(1,3), node.matrix(3,3));
DxfData *dd = N.convertToDxfData();
for (size_t i=0; i < dd->points.size(); i++) {
CGAL_Kernel2::Point_2 p = CGAL_Kernel2::Point_2(dd->points[i][0], dd->points[i][1]);
p = t.transform(p);
dd->points[i][0] = to_double(p.x());
dd->points[i][1] = to_double(p.y());
Eigen::Matrix2f testmat;
testmat << node.matrix(0,0), node.matrix(0,1), node.matrix(1,0), node.matrix(1,1);
if (testmat.determinant() == 0) {
PRINT("Warning: Scaling a 2D object with 0 - removing object");
N.p2.reset();
}
else {
CGAL_Aff_transformation2 t(
node.matrix(0,0), node.matrix(0,1), node.matrix(0,3),
node.matrix(1,0), node.matrix(1,1), node.matrix(1,3), node.matrix(3,3));
DxfData *dd = N.convertToDxfData();
for (size_t i=0; i < dd->points.size(); i++) {
CGAL_Kernel2::Point_2 p = CGAL_Kernel2::Point_2(dd->points[i][0], dd->points[i][1]);
p = t.transform(p);
dd->points[i][0] = to_double(p.x());
dd->points[i][1] = to_double(p.y());
}
PolySet ps;
ps.is2d = true;
dxf_tesselate(&ps, *dd, 0, true, false, 0);
N = evaluateCGALMesh(ps);
delete dd;
}
PolySet ps;
ps.is2d = true;
dxf_tesselate(&ps, *dd, 0, true, false, 0);
N = evaluateCGALMesh(ps);
delete dd;
}
else if (N.dim == 3) {
CGAL_Aff_transformation t(
node.matrix(0,0), node.matrix(0,1), node.matrix(0,2), node.matrix(0,3),
node.matrix(1,0), node.matrix(1,1), node.matrix(1,2), node.matrix(1,3),
node.matrix(2,0), node.matrix(2,1), node.matrix(2,2), node.matrix(2,3), node.matrix(3,3));
N.p3->transform(t);
if (node.matrix.matrix().determinant() == 0) {
PRINT("Warning: Scaling a 3D object with 0 - removing object");
N.p3.reset();
}
else {
CGAL_Aff_transformation t(
node.matrix(0,0), node.matrix(0,1), node.matrix(0,2), node.matrix(0,3),
node.matrix(1,0), node.matrix(1,1), node.matrix(1,2), node.matrix(1,3),
node.matrix(2,0), node.matrix(2,1), node.matrix(2,2), node.matrix(2,3), node.matrix(3,3));
N.p3->transform(t);
}
}
}
else {

View File

@ -61,6 +61,8 @@ CGAL_Nef_polyhedron &CGAL_Nef_polyhedron::minkowski(const CGAL_Nef_polyhedron &o
int CGAL_Nef_polyhedron::weight() const
{
if (this->empty()) return 0;
size_t memsize = sizeof(CGAL_Nef_polyhedron);
if (this->dim == 2) {
memsize += sizeof(CGAL_Nef_polyhedron2) +

View File

@ -281,12 +281,14 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const LinearExtrudeNode &node)
BOOST_FOREACH (AbstractNode * v, node.getChildren()) {
if (v->modinst->isBackground()) continue;
CGAL_Nef_polyhedron N = this->cgalevaluator.evaluateCGALMesh(*v);
if (N.dim != 2) {
PRINT("ERROR: linear_extrude() is not defined for 3D child objects!");
}
else {
if (sum.empty()) sum = N.copy();
else sum += N;
if (!N.empty()) {
if (N.dim != 2) {
PRINT("ERROR: linear_extrude() is not defined for 3D child objects!");
}
else {
if (sum.empty()) sum = N.copy();
else sum += N;
}
}
}
@ -379,12 +381,14 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const RotateExtrudeNode &node)
BOOST_FOREACH (AbstractNode * v, node.getChildren()) {
if (v->modinst->isBackground()) continue;
CGAL_Nef_polyhedron N = this->cgalevaluator.evaluateCGALMesh(*v);
if (N.dim != 2) {
PRINT("ERROR: rotate_extrude() is not defined for 3D child objects!");
}
else {
if (sum.empty()) sum = N.copy();
else sum += N;
if (!N.empty()) {
if (N.dim != 2) {
PRINT("ERROR: rotate_extrude() is not defined for 3D child objects!");
}
else {
if (sum.empty()) sum = N.copy();
else sum += N;
}
}
}

View File

@ -87,11 +87,10 @@ AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstanti
{
Vector3d scalevec(1,1,1);
Value v = c.lookup_variable("v");
v.getnum(scalevec[0]);
v.getnum(scalevec[1]);
v.getnum(scalevec[2]);
v.getv3(scalevec[0], scalevec[1], scalevec[2]);
if (scalevec[2] == 0) scalevec[2] = 1;
if (!v.getv3(scalevec[0], scalevec[1], scalevec[2], 1.0)) {
double num;
if (v.getnum(num)) scalevec.setConstant(num);
}
node->matrix.scale(scalevec);
}
else if (this->type == ROTATE)

View File

@ -359,11 +359,11 @@ bool Value::getv2(double &x, double &y) const
return true;
}
bool Value::getv3(double &x, double &y, double &z) const
bool Value::getv3(double &x, double &y, double &z, double defaultval) const
{
if (this->type == VECTOR && this->vec.size() == 2) {
if (getv2(x, y)) {
z = 0;
z = defaultval;
return true;
}
return false;

View File

@ -73,7 +73,7 @@ public:
bool getnum(double &v) const;
bool getv2(double &x, double &y) const;
bool getv3(double &x, double &y, double &z) const;
bool getv3(double &x, double &y, double &z, double defaultval = 0.0) const;
std::string toString() const;

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

View File

@ -0,0 +1,34 @@
multmatrix([[2, 0, 0, 0], [0, 1.33333, 0, 0], [0, 0, 2, 0], [0, 0, 0, 1]]) {
group() {
square(size = [2, 3], center = true);
}
}
multmatrix([[1, 0, 0, 5], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
multmatrix([[2, 0, 0, 0], [0, 1.33333, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
group() {
square(size = [2, 3], center = true);
}
}
}
multmatrix([[1, 0, 0, 10], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
multmatrix([[2, 0, 0, 0], [0, 2, 0, 0], [0, 0, 2, 0], [0, 0, 0, 1]]) {
group() {
square(size = [2, 3], center = true);
}
}
}
linear_extrude(height = 100, center = false, convexity = 1, $fn = 0, $fa = 12, $fs = 2) {
multmatrix([[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
group() {
square(size = [2, 3], center = true);
}
}
}
linear_extrude(height = 100, center = false, convexity = 1, $fn = 0, $fa = 12, $fs = 2) {
multmatrix([[0, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
group() {
square(size = [2, 3], center = true);
}
}
}

View File

@ -0,0 +1,43 @@
multmatrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
multmatrix([[1, 0, 0, 0], [0, 2, 0, 0], [0, 0, 3, 0], [0, 0, 0, 1]]) {
group() {
cylinder($fn = 8, $fa = 12, $fs = 2, h = 1, r1 = 1, r2 = 1, center = true);
}
}
}
multmatrix([[1, 0, 0, 5], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
multmatrix([[2, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
group() {
cylinder($fn = 8, $fa = 12, $fs = 2, h = 1, r1 = 1, r2 = 1, center = true);
}
}
}
multmatrix([[1, 0, 0, 10], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
multmatrix([[2, 0, 0, 0], [0, 2, 0, 0], [0, 0, 2, 0], [0, 0, 0, 1]]) {
group() {
cylinder($fn = 8, $fa = 12, $fs = 2, h = 1, r1 = 1, r2 = 1, center = true);
}
}
}
linear_extrude(height = 100, center = false, convexity = 1, $fn = 0, $fa = 12, $fs = 2) {
multmatrix([[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 1]]) {
group() {
cylinder($fn = 8, $fa = 12, $fs = 2, h = 1, r1 = 1, r2 = 1, center = true);
}
}
}
linear_extrude(height = 100, center = false, convexity = 1, $fn = 0, $fa = 12, $fs = 2) {
multmatrix([[0, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 0], [0, 0, 0, 1]]) {
group() {
cylinder($fn = 8, $fa = 12, $fs = 2, h = 1, r1 = 1, r2 = 1, center = true);
}
}
}
linear_extrude(height = 100, center = false, convexity = 1, $fn = 0, $fa = 12, $fs = 2) {
multmatrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 0], [0, 0, 0, 1]]) {
group() {
cylinder($fn = 8, $fa = 12, $fs = 2, h = 1, r1 = 1, r2 = 1, center = true);
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB