summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xscripts/check-dependencies.sh2
-rwxr-xr-xscripts/uni-build-dependencies.sh20
-rw-r--r--setenv_mjau.sh2
-rw-r--r--src/Preferences.cc8
-rw-r--r--src/control.cc6
-rw-r--r--src/csgtermnormalizer.cc2
-rw-r--r--src/func.cc8
-rw-r--r--src/mainwin.cc17
-rw-r--r--src/openscad.cc10
-rw-r--r--src/svg.cc3
-rw-r--r--testdata/scad/bugs/issue267-normalization-crash.scad86
11 files changed, 144 insertions, 20 deletions
diff --git a/scripts/check-dependencies.sh b/scripts/check-dependencies.sh
index eaed556..6a3e637 100755
--- a/scripts/check-dependencies.sh
+++ b/scripts/check-dependencies.sh
@@ -449,7 +449,7 @@ check_old_local()
warnon=
if [ "`uname | grep -i linux`" ]; then
header_list="opencsg.h CGAL boost GL/glew.h gmp.h mpfr.h eigen2 eigen3"
- liblist="libboost libopencsg libCGAL libglew"
+ liblist="libboost_system libboost_system-mt libopencsg libCGAL libglew"
for i in $header_list $liblist; do
if [ -e /usr/local/include/$i ]; then
echo "Warning: you have a copy of "$i" under /usr/local/include"
diff --git a/scripts/uni-build-dependencies.sh b/scripts/uni-build-dependencies.sh
index bf5ca1c..09b6b79 100755
--- a/scripts/uni-build-dependencies.sh
+++ b/scripts/uni-build-dependencies.sh
@@ -232,16 +232,28 @@ build_boost()
fi
fi
# We only need certain portions of boost
- ./bootstrap.sh --prefix=$DEPLOYDIR --with-libraries=thread,program_options,filesystem,system,regex
+ if [ -e ./bootstrap.sh ]; then
+ BSTRAPBIN=./bootstrap.sh
+ else
+ BSTRAPBIN=./configure
+ fi
+ $BSTRAPBIN --prefix=$DEPLOYDIR --with-libraries=thread,program_options,filesystem,system,regex
+ if [ -e ./b2 ]; then
+ BJAMBIN=./b2;
+ elif [ -e ./bjam ]; then
+ BJAMBIN=./bjam
+ elif [ -e ./Makefile ]; then
+ BJAMBIN=make
+ fi
if [ $CXX ]; then
if [ $CXX = "clang++" ]; then
- ./b2 -j$NUMCPU toolset=clang install
+ $BJAMBIN -j$NUMCPU toolset=clang install
# ./b2 -j$NUMCPU toolset=clang cxxflags="-stdlib=libc++" linkflags="-stdlib=libc++" install
fi
else
- ./b2 -j$NUMCPU
+ $BJAMBIN -j$NUMCPU
if [ $? = 0 ]; then
- ./b2 install
+ $BJAMBIN install
else
echo boost build failed
exit 1
diff --git a/setenv_mjau.sh b/setenv_mjau.sh
index 677a47a..943ae6b 100644
--- a/setenv_mjau.sh
+++ b/setenv_mjau.sh
@@ -6,7 +6,7 @@ export QMAKESPEC=macx-g++
#export CGALDIR=$PWD/../install/CGAL-3.6
#export DYLD_LIBRARY_PATH=$OPENCSGDIR/lib
-# Own own Qt
+# Our own Qt
export PATH=$OPENSCAD_LIBRARIES/bin:$PATH
# ccache:
diff --git a/src/Preferences.cc b/src/Preferences.cc
index e70a2a1..ec66094 100644
--- a/src/Preferences.cc
+++ b/src/Preferences.cc
@@ -30,7 +30,9 @@
#include <QKeyEvent>
#include <QSettings>
#include "PolySetCache.h"
+#ifdef ENABLE_CGAL
#include "CGALCache.h"
+#endif
Preferences *Preferences::instance = NULL;
@@ -75,7 +77,9 @@ Preferences::Preferences(QWidget *parent) : QMainWindow(parent)
this->defaultmap["advanced/opencsg_show_warning"] = true;
this->defaultmap["advanced/enable_opencsg_opengl1x"] = true;
this->defaultmap["advanced/polysetCacheSize"] = uint(PolySetCache::instance()->maxSize());
+#ifdef ENABLE_CGAL
this->defaultmap["advanced/cgalCacheSize"] = uint(CGALCache::instance()->maxSize());
+#endif
this->defaultmap["advanced/openCSGLimit"] = 2000;
this->defaultmap["advanced/forceGoldfeather"] = false;
@@ -126,7 +130,9 @@ Preferences::Preferences(QWidget *parent) : QMainWindow(parent)
// Advanced pane
QValidator *validator = new QIntValidator(this);
+#ifdef ENABLE_CGAL
this->cgalCacheSizeEdit->setValidator(validator);
+#endif
this->polysetCacheSizeEdit->setValidator(validator);
this->opencsgLimitEdit->setValidator(validator);
@@ -198,7 +204,9 @@ void Preferences::on_cgalCacheSizeEdit_textChanged(const QString &text)
{
QSettings settings;
settings.setValue("advanced/cgalCacheSize", text);
+#ifdef ENABLE_CGAL
CGALCache::instance()->setMaxSize(text.toULong());
+#endif
}
void Preferences::on_polysetCacheSizeEdit_textChanged(const QString &text)
diff --git a/src/control.cc b/src/control.cc
index bdd0f40..44847f5 100644
--- a/src/control.cc
+++ b/src/control.cc
@@ -96,8 +96,10 @@ AbstractNode *ControlModule::evaluate(const Context*, const ModuleInstantiation
size_t n = 0;
if (inst->argvalues.size() > 0) {
double v;
- if (inst->argvalues[0].getDouble(v))
- n = v;
+ if (inst->argvalues[0].getDouble(v)) {
+ if (v < 0) return NULL; // Disallow negative child indices
+ n = trunc(v);
+ }
}
for (int i = Context::ctx_stack.size()-1; i >= 0; i--) {
const Context *c = Context::ctx_stack[i];
diff --git a/src/csgtermnormalizer.cc b/src/csgtermnormalizer.cc
index e2474e9..81fab80 100644
--- a/src/csgtermnormalizer.cc
+++ b/src/csgtermnormalizer.cc
@@ -20,7 +20,7 @@ shared_ptr<CSGTerm> CSGTermNormalizer::normalize(const shared_ptr<CSGTerm> &root
PRINTB("WARNING: Normalized tree is growing past %d elements. Aborting normalization.\n", this->limit);
// Clean up any partially evaluated terms
shared_ptr<CSGTerm> newroot = root, tmproot;
- while (newroot != tmproot) {
+ while (newroot && newroot != tmproot) {
tmproot = newroot;
newroot = collapse_null_terms(tmproot);
}
diff --git a/src/func.cc b/src/func.cc
index 5dcb3e9..791e957 100644
--- a/src/func.cc
+++ b/src/func.cc
@@ -43,7 +43,7 @@
*/
#include <boost/random/mersenne_twister.hpp>
-#include <boost/random/uniform_real_distribution.hpp>
+#include <boost/random/uniform_real.hpp>
#ifdef __WIN32__
#include <process.h>
@@ -54,8 +54,8 @@ int process_id = _getpid();
int process_id = getpid();
#endif
-boost::random::mt19937 deterministic_rng;
-boost::random::mt19937 lessdeterministic_rng( std::time(0) + process_id );
+boost::mt19937 deterministic_rng;
+boost::mt19937 lessdeterministic_rng( std::time(0) + process_id );
AbstractFunction::~AbstractFunction()
{
@@ -167,7 +167,7 @@ Value builtin_rands(const Context *, const std::vector<std::string>&, const std:
double min = std::min( args[0].toDouble(), args[1].toDouble() );
double max = std::max( args[0].toDouble(), args[1].toDouble() );
- boost::random::uniform_real_distribution<> distributor( min, max );
+ boost::uniform_real<> distributor( min, max );
Value::VectorType vec;
for (int i=0; i<args[2].toDouble(); i++) {
if ( deterministic ) {
diff --git a/src/mainwin.cc b/src/mainwin.cc
index 251c6e1..17b9ef7 100644
--- a/src/mainwin.cc
+++ b/src/mainwin.cc
@@ -89,6 +89,10 @@
#include "cgal.h"
#include "cgalworker.h"
+#else
+
+#include "PolySetEvaluator.h"
+
#endif // ENABLE_CGAL
#ifndef OPENCSG_VERSION_STRING
@@ -153,9 +157,11 @@ MainWindow::MainWindow(const QString &filename)
{
setupUi(this);
+#ifdef ENABLE_CGAL
this->cgalworker = new CGALWorker();
connect(this->cgalworker, SIGNAL(done(CGAL_Nef_polyhedron *)),
this, SLOT(actionRenderCGALDone(CGAL_Nef_polyhedron *)));
+#endif
register_builtin(root_ctx);
@@ -410,8 +416,10 @@ MainWindow::loadDesignSettings()
}
uint polySetCacheSize = Preferences::inst()->getValue("advanced/polysetCacheSize").toUInt();
PolySetCache::instance()->setMaxSize(polySetCacheSize);
+#ifdef ENABLE_CGAL
uint cgalCacheSize = Preferences::inst()->getValue("advanced/cgalCacheSize").toUInt();
CGALCache::instance()->setMaxSize(cgalCacheSize);
+#endif
}
MainWindow::~MainWindow()
@@ -677,8 +685,12 @@ void MainWindow::compileCSG(bool procevents)
progress_report_prep(this->root_node, report_func, this);
try {
+#ifdef ENABLE_CGAL
CGALEvaluator cgalevaluator(this->tree);
PolySetCGALEvaluator psevaluator(cgalevaluator);
+#else
+ PolySetEvaluator psevaluator(this->tree);
+#endif
CSGTermEvaluator csgrenderer(this->tree, &psevaluator);
this->root_raw_term = csgrenderer.evaluateCSGTerm(*root_node, highlight_terms, background_terms);
if (!root_raw_term) {
@@ -687,7 +699,9 @@ void MainWindow::compileCSG(bool procevents)
QApplication::processEvents();
}
PolySetCache::instance()->print();
+#ifdef ENABLE_CGAL
CGALCache::instance()->print();
+#endif
}
catch (const ProgressCancelException &e) {
PRINT("CSG generation cancelled.");
@@ -1196,8 +1210,9 @@ void MainWindow::actionRenderCGALDone(CGAL_Nef_polyhedron *root_N)
if (root_N) {
PolySetCache::instance()->print();
+#ifdef ENABLE_CGAL
CGALCache::instance()->print();
-
+#endif
if (!root_N->isNull()) {
if (root_N->dim == 2) {
PRINT(" Top level object is a 2D object:");
diff --git a/src/openscad.cc b/src/openscad.cc
index 472b5d4..880aa0d 100644
--- a/src/openscad.cc
+++ b/src/openscad.cc
@@ -255,7 +255,6 @@ int main(int argc, char **argv)
if (!filename) help(argv[0]);
-#ifdef ENABLE_CGAL
Context root_ctx;
register_builtin(root_ctx);
@@ -299,6 +298,7 @@ int main(int argc, char **argv)
}
}
else {
+#ifdef ENABLE_CGAL
CGAL_Nef_polyhedron root_N = cgalevaluator.evaluateCGALMesh(*tree.root());
fs::current_path(original_path);
@@ -373,12 +373,12 @@ int main(int argc, char **argv)
fstream.close();
}
}
- }
- delete root_node;
#else
- fprintf(stderr, "OpenSCAD has been compiled without CGAL support!\n");
- exit(1);
+ fprintf(stderr, "OpenSCAD has been compiled without CGAL support!\n");
+ exit(1);
#endif
+ }
+ delete root_node;
}
else if (useGUI)
{
diff --git a/src/svg.cc b/src/svg.cc
index e5130b0..66e5797 100644
--- a/src/svg.cc
+++ b/src/svg.cc
@@ -1,3 +1,4 @@
+#ifdef ENABLE_CGAL
#include "cgalutils.h"
#include "svg.h"
#include <boost/algorithm/string.hpp>
@@ -246,4 +247,4 @@ std::string dump_svg( const CGAL_Nef_polyhedron3 &N )
} // namespace
-
+#endif // ENABLE_CGAL
diff --git a/testdata/scad/bugs/issue267-normalization-crash.scad b/testdata/scad/bugs/issue267-normalization-crash.scad
new file mode 100644
index 0000000..e4e3d87
--- /dev/null
+++ b/testdata/scad/bugs/issue267-normalization-crash.scad
@@ -0,0 +1,86 @@
+/*
+ * Reported by Justin Charette
+ * Causes a crash in CSGTermNormalizer::normalize() when CSG element count
+ * exceeds limit setting in preferences (verified with default value of 2000).
+ */
+
+
+$fn=20;
+
+/* donut (r1, r2, t) {{{
+ r1 = radius of torus
+ r2 = radius of torus cross section (circle)
+ t = thickness of shell (t == 0 is
+*/
+module donut (r1, r2, t=0) {
+ difference() {
+ rotate_extrude( convexity=6 ) {
+ translate([r1, 0, 0]) {
+ circle( r = r2 );
+ }
+ }
+ // (t == 0 ? solid : hollow )
+ if (t > 0) {
+ rotate_extrude( convexity=6 ) {
+ translate([r1, 0, 0]) {
+ circle( r = r2-t );
+ }
+ }
+ }
+ }
+} //}}}
+
+/* half donut (r1, r2, t, round) {{{
+ r1 = radius of torus
+ r2 = radius of torus cross section (circle)
+ t = thickness of shell
+ round = trim ends of semi-torus so they are round
+*/
+module half_donut (r1, r2, t=1, round=false) {
+ difference() {
+ donut( r1, r2, t );
+ difference() {
+ translate( [0, -((r1+r2)/2+0.5), 0] )
+ scale( [2*(r1+r2)+1, r1+r2+1, 2*r2+1] )
+ square( 1, center=true );
+ if (round) {
+ rotate( 90, [0, 1, 0] )
+ cylinder( 2*(r1+r2)+2, r2, r2, center=true );
+ }
+ }
+ }
+} //}}}
+
+/* donut flange (r1, r2, a1, a2, a_step, t, round) {{{
+ r1 = radius of torus
+ r2 = radius of torus cross section (circle)
+ a1 = starting angle of flange rotation
+ a2 = stopping angle of flange rotation
+ a_step = increment size of flange rotation
+ t = thickness of shell (t == 0 is solid, t in (0, r2) is hollow)
+ round = (true/false) to trim ends of semi-torus so they are round
+*/
+module donut_flange (r1, r2, a1, a2, a_step=1, t=0, round=false) {
+ difference() {
+ union() {
+ for (a = [a1:a_step:a2]) {
+ rotate( a, [1, 0, 0] )
+ half_donut( r1, r2, round );
+ }
+ }
+ // (t == 0 ? solid : hollow )
+ if (t > 0) {
+ union() {
+ for (a = [a1:a_step:a2]) {
+ rotate( a, [1, 0, 0] )
+ half_donut( r1, r2-t, round );
+ }
+ }
+ }
+ }
+} //}}}
+
+donut( 20, 5 );
+donut_flange( 20, 5, 0, 50, 10, t=1, round=false );
+
+// vim: set et sw=2 ts=2 sts=2 ai sta sr fdm=marker:
contact: Jan Huwald // Impressum