diff --git a/dw/types.cc b/dw/types.cc index e49847c..be27005 100644 --- a/dw/types.cc +++ b/dw/types.cc @@ -231,8 +231,14 @@ void Region::addRectangle (Rectangle *rPointer) auto r= std::make_unique< Rectangle >( rPointer->x, rPointer->y, rPointer->width, rPointer->height ); - for( auto &ownRect: rectangleList ) + for( auto it= rectangleList.begin(); it != rectangleList.end(); ) { + // We have to increment immediately. The removal of the element, near the bottom + // of this loop will invalidate any iterators pointing into the rectangleList at + // that position. A range-based for loop will increment the iterator after the + // current pass, which would cause crashes. + auto &ownRect= *it++; + int combinedHeight = misc::max(r->y + r->height, ownRect->y + ownRect->height) - misc::min(r->y, ownRect->y);