From 07798510fc8ea2150a80ccd00efd7b63d151314d Mon Sep 17 00:00:00 2001 From: bubnikv <bubnikv@gmail.com> Date: Thu, 5 Sep 2019 14:29:34 +0200 Subject: [PATCH 1/4] Fighting the ASCII STL import. Fix of 2.1.0-rc: Loading MMU STL's results in object placement off the plater (#2868) It has been broken with 9abef2241d188d0cc0892bc3070d7360749c2702 when trying to fix "Error on importing stl" #2813 --- src/admesh/stlinit.cpp | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/admesh/stlinit.cpp b/src/admesh/stlinit.cpp index f37c4af07..bbf6d3dd5 100644 --- a/src/admesh/stlinit.cpp +++ b/src/admesh/stlinit.cpp @@ -162,24 +162,31 @@ static bool stl_read(stl_file *stl, FILE *fp, int first_facet, bool first) // Read a single facet from an ASCII .STL file // skip solid/endsolid // (in this order, otherwise it won't work when they are paired in the middle of a file) - fscanf(fp, "endsolid %*[^\n]\n"); - fscanf(fp, "solid %*[^\n]\n"); // name might contain spaces so %*s doesn't work and it also can be empty (just "solid") + fscanf(fp, " endsolid%*[^\n]\n"); + fscanf(fp, " solid%*[^\n]\n"); // name might contain spaces so %*s doesn't work and it also can be empty (just "solid") // Leading space in the fscanf format skips all leading white spaces including numerous new lines and tabs. - int res_normal = fscanf(fp, " facet normal %31s %31s %31s ", normal_buf[0], normal_buf[1], normal_buf[2]); + int res_normal = fscanf(fp, " facet normal %31s %31s %31s", normal_buf[0], normal_buf[1], normal_buf[2]); assert(res_normal == 3); - int res_outer_loop = fscanf(fp, " outer loop "); + int res_outer_loop = fscanf(fp, " outer loop"); assert(res_outer_loop == 0); - int res_vertex1 = fscanf(fp, " vertex %f %f %f ", &facet.vertex[0](0), &facet.vertex[0](1), &facet.vertex[0](2)); + int res_vertex1 = fscanf(fp, " vertex %f %f %f", &facet.vertex[0](0), &facet.vertex[0](1), &facet.vertex[0](2)); assert(res_vertex1 == 3); - int res_vertex2 = fscanf(fp, " vertex %f %f %f ", &facet.vertex[1](0), &facet.vertex[1](1), &facet.vertex[1](2)); + int res_vertex2 = fscanf(fp, " vertex %f %f %f", &facet.vertex[1](0), &facet.vertex[1](1), &facet.vertex[1](2)); assert(res_vertex2 == 3); + // Trailing whitespace is there to eat all whitespaces and empty lines up to the next non-whitespace. int res_vertex3 = fscanf(fp, " vertex %f %f %f ", &facet.vertex[2](0), &facet.vertex[2](1), &facet.vertex[2](2)); assert(res_vertex3 == 3); - int res_endloop = fscanf(fp, " endloop %*[^\n]\n"); - assert(res_endloop == 0); - // There is a leading and trailing white space around endfacet to eat up all leading and trailing white spaces including numerous tabs and new lines. - int res_endfacet = fscanf(fp, " endfacet %*[^\n]\n"); - if (res_normal != 3 || res_outer_loop != 0 || res_vertex1 != 3 || res_vertex2 != 3 || res_vertex3 != 3 || res_endloop != 0 || res_endfacet != 0) { + // Some G-code generators tend to produce text after "endloop" and "endfacet". Just ignore it. + char buf[2048]; + fgets(buf, 2047, fp); + bool endloop_ok = strncmp(buf, "endloop", 7) == 0 && (buf[7] == '\n' || buf[7] == ' ' || buf[7] == '\t'); + assert(endloop_ok); + // Skip the trailing whitespaces and empty lines. + fscanf(fp, " "); + fgets(buf, 2047, fp); + bool endfacet_ok = strncmp(buf, "endfacet", 8) == 0 && (buf[8] == '\n' || buf[8] == ' ' || buf[8] == '\t'); + assert(endfacet_ok); + if (res_normal != 3 || res_outer_loop != 0 || res_vertex1 != 3 || res_vertex2 != 3 || res_vertex3 != 3 || ! endloop_ok || ! endfacet_ok) { BOOST_LOG_TRIVIAL(error) << "Something is syntactically very wrong with this ASCII STL! "; return false; } From bda0246b5de9908f7398eae8f30de55bb28c2359 Mon Sep 17 00:00:00 2001 From: Enrico Turri <enricoturri@seznam.cz> Date: Fri, 6 Sep 2019 09:44:39 +0200 Subject: [PATCH 2/4] Fix of #2868 -> Revert 2c9521c6d246beab98dac248bbfa85046fe02c4d and partial revert of fab363493140a93c1786c7898424a73dd1ed2a2e --- src/libslic3r/Model.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index 5121a1fe2..7526dd16a 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -529,8 +529,9 @@ void Model::convert_multipart_object(unsigned int max_extruders) } } - object->add_instance(); - object->instances[0]->set_offset(object->raw_mesh_bounding_box().center()); + // commented-out to fix #2868 +// object->add_instance(); +// object->instances[0]->set_offset(object->raw_mesh_bounding_box().center()); this->clear_objects(); this->objects.push_back(object); From 3b498f687cfa3b6a5d2e81a185eca844f710eb99 Mon Sep 17 00:00:00 2001 From: Vojtech Kral <vojtech@kral.hk> Date: Fri, 6 Sep 2019 15:02:01 +0200 Subject: [PATCH 3/4] Fix a few error messages in avrdude --- src/avrdude/ser_posix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/avrdude/ser_posix.c b/src/avrdude/ser_posix.c index e2afd1c09..9992f78e3 100644 --- a/src/avrdude/ser_posix.c +++ b/src/avrdude/ser_posix.c @@ -90,7 +90,7 @@ static speed_t serial_baud_lookup(long baud) * If a non-standard BAUD rate is used, issue * a warning (if we are verbose) and return the raw rate */ - avrdude_message(MSG_NOTICE, "%s: serial_baud_lookup(): Using non-standard baud rate: %ld", + avrdude_message(MSG_NOTICE, "%s: serial_baud_lookup(): Using non-standard baud rate: %ld\n", progname, baud); return baud; @@ -110,7 +110,7 @@ static int ser_setspeed(union filedescriptor *fd, long baud) */ rc = tcgetattr(fd->ifd, &termios); if (rc < 0) { - avrdude_message(MSG_INFO, "%s: ser_setspeed(): tcgetattr() failed", + avrdude_message(MSG_INFO, "%s: ser_setspeed(): tcgetattr() failed\n", progname); return -errno; } From 34821df6eb119b725c6e05596a4e73d3d6c69d37 Mon Sep 17 00:00:00 2001 From: Vojtech Kral <vojtech@kral.hk> Date: Fri, 6 Sep 2019 14:50:44 +0200 Subject: [PATCH 4/4] Fix bad pointer dereference in ObjectList::list_manipulation() Fix of #2875 --- src/slic3r/GUI/GUI_ObjectList.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 20760e2bc..7ba26f471 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -789,16 +789,11 @@ void ObjectList::OnContextMenu(wxDataViewEvent&) void ObjectList::list_manipulation() { wxDataViewItem item; - wxDataViewColumn* col; + wxDataViewColumn* col = nullptr; const wxPoint pt = get_mouse_position_in_control(); HitTest(pt, item, col); -#ifdef __WXOSX__ // temporary workaround for OSX - // after Yosemite OS X version, HitTest return undefined item - if (!item) item = GetSelection(); -#endif // __WXOSX__ - if (!item) { - printf("undefined item\n"); + if (!item || col == nullptr) { return; }