diff --git a/src/zm_image.cpp b/src/zm_image.cpp index 8c7189e6b..3fbb458f5 100644 --- a/src/zm_image.cpp +++ b/src/zm_image.cpp @@ -2720,9 +2720,12 @@ void Image::Fill(Rgb colour, int density, const Polygon &polygon) { std::sort(active_edges.begin(), active_edges.end(), PolygonFill::Edge::CompareX); if (!(scan_line % density)) { - for (auto it = active_edges.begin(); it < active_edges.end() - 1; ++it) { + // Fill between pairs of active edges (parity rule). Stepping one + // edge at a time would incorrectly fill the gaps between arms of + // a non-convex polygon (e.g. a banana shape). + for (auto it = active_edges.begin(); it + 1 < active_edges.end(); it += 2) { int32 lo_x = static_cast(it->min_x); - int32 hi_x = static_cast(std::next(it)->min_x); + int32 hi_x = static_cast((it + 1)->min_x); if (colours == ZM_COLOUR_GRAY8) { uint8 *p = &buffer[(scan_line * width) + lo_x];