From 33cb7db2dd871737863233c700f21bde8b10fd17d159a1f0ca6d8ac410451668 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Sat, 9 Aug 2025 04:58:51 -0400 Subject: [PATCH] Fix rectangles bug. --- dw/types.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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);