Skip to content

Commit

Permalink
Fixed potential hang in PerimeterGenerator.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
alranel committed Aug 6, 2015
1 parent 6ac79e3 commit 5b8ed73
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions xs/src/libslic3r/PerimeterGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ PerimeterGenerator::process()
for (Surfaces::const_iterator surface = this->slices->surfaces.begin();
surface != this->slices->surfaces.end(); ++surface) {
// detect how many perimeters must be generated for this island
unsigned short loop_number = this->config->perimeters + surface->extra_perimeters;
short loop_number = this->config->perimeters + surface->extra_perimeters;
loop_number--; // 0-indexed loops

Polygons gaps;
Expand Down Expand Up @@ -187,7 +187,7 @@ PerimeterGenerator::process()
}

// if no hole contains this hole, find the contour loop that contains it
for (unsigned short t = loop_number; t >= 0; --t) {
for (short t = loop_number; t >= 0; --t) {
for (unsigned short j = 0; j < contours[t].size(); ++j) {
PerimeterGeneratorLoop &candidate_parent = contours[t][j];
if (candidate_parent.polygon.contains(loop.polygon.first_point())) {
Expand All @@ -203,15 +203,15 @@ PerimeterGenerator::process()
}

// nest contour loops
for (unsigned short d = loop_number; d >= 1; --d) {
for (short d = loop_number; d >= 1; --d) {
PerimeterGeneratorLoops &contours_d = contours[d];

// loop through all contours having depth == d
for (unsigned short i = 0; i < contours_d.size(); ++i) {
const PerimeterGeneratorLoop &loop = contours_d[i];

// find the contour loop that contains it
for (unsigned short t = d-1; t >= 0; --t) {
for (short t = d-1; t >= 0; --t) {
for (unsigned short j = 0; j < contours[t].size(); ++j) {
PerimeterGeneratorLoop &candidate_parent = contours[t][j];
if (candidate_parent.polygon.contains(loop.polygon.first_point())) {
Expand Down

2 comments on commit 5b8ed73

@ntfshard
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you use an unsigned short in this file? (Some other places are still unsigned short.)
It can works much slower (Typically, CPUs are fastest at operating on integers of their native word size) and this type can handle just ~65k.

P.S.Iterators are great;

@alranel
Copy link
Member Author

@alranel alranel commented on 5b8ed73 Aug 7, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think nobody will use more than ~65k perimeters :-)

If it's slower, we can use int.

Please sign in to comment.