From bf2771d6d7126dcde47541c72ab5eba7bb34b0c8 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Fri, 23 Jul 2021 18:38:55 +0200 Subject: [PATCH] Check if stack of graphics states is empty while attempting to reset the clip For macOS < 10.13 there is not available any method to really reset the clipping region so ResetClip() is implemented using hack that works for sure only if no graphics state was stored before on the stack with PushState(). If ResetClip() is called when some graphics states are already stored with PushState() we can only warn that resetting the clip may be not effective. See #19231. --- src/osx/carbon/graphics.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/osx/carbon/graphics.cpp b/src/osx/carbon/graphics.cpp index 4506e90931..36ccab6406 100644 --- a/src/osx/carbon/graphics.cpp +++ b/src/osx/carbon/graphics.cpp @@ -2141,6 +2141,12 @@ void wxMacCoreGraphicsContext::ResetClip() { // there is no way for clearing the clip, we can only revert to the stored // state, but then we have to make sure everything else is NOT restored + // Note: This trick works as expected only if a state with no clipping + // path is stored on the top of the stack. It's guaranteed to work only + // when no PushState() was called before because in this case a reference + // state (initial state without clipping region) is on the top of the stack. + wxASSERT_MSG(m_stateStackLevel == 0, + "Resetting the clip may not work when PushState() was called before"); CGAffineTransform transform = CGContextGetCTM( m_cgContext ); CGContextRestoreGState( m_cgContext ); CGContextSaveGState( m_cgContext );