From c545ca04928c4ff0d36f5469a5bb481f9f582231 Mon Sep 17 00:00:00 2001 From: Anthony Nicholls Date: Thu, 3 Oct 2024 08:36:14 +0100 Subject: [PATCH] CoreGraphics: Prevent an assertion when creating a rounded rectangle --- .../native/juce_CoreGraphicsContext_mac.mm | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/juce_graphics/native/juce_CoreGraphicsContext_mac.mm b/modules/juce_graphics/native/juce_CoreGraphicsContext_mac.mm index d18578ad9b..928fe73c1e 100644 --- a/modules/juce_graphics/native/juce_CoreGraphicsContext_mac.mm +++ b/modules/juce_graphics/native/juce_CoreGraphicsContext_mac.mm @@ -638,7 +638,10 @@ void CoreGraphicsContext::drawRoundedRectangle (const Rectangle& r, float CGContextSetLineCap (context.get(), kCGLineCapButt); CGContextSetLineJoin (context.get(), kCGLineJoinMiter); - detail::PathPtr path { CGPathCreateWithRoundedRect (convertToCGRectFlipped (r), cornerSize, cornerSize, nullptr) }; + detail::PathPtr path { CGPathCreateWithRoundedRect (convertToCGRectFlipped (r), + std::clamp (cornerSize, 0.0f, r.getWidth() / 2.0f), + std::clamp (cornerSize, 0.0f, r.getHeight() / 2.0f), + nullptr) }; CGContextAddPath (context.get(), path.get()); drawCurrentPath (kCGPathStroke); } @@ -669,7 +672,10 @@ void CoreGraphicsContext::drawRoundedRectangle (const Rectangle& r, float void CoreGraphicsContext::fillRoundedRectangle (const Rectangle& r, float cornerSize) { CGContextBeginPath (context.get()); - detail::PathPtr path { CGPathCreateWithRoundedRect (convertToCGRectFlipped (r), cornerSize, cornerSize, nullptr) }; + detail::PathPtr path { CGPathCreateWithRoundedRect (convertToCGRectFlipped (r), + std::clamp (cornerSize, 0.0f, r.getWidth() / 2.0f), + std::clamp (cornerSize, 0.0f, r.getHeight() / 2.0f), + nullptr) }; CGContextAddPath (context.get(), path.get()); drawCurrentPath (kCGPathFill); }