Fix crash from CGRect.null in crop guide constraint updates - #283
Open
ohlulu wants to merge 1 commit into
Open
Conversation
CGRect.intersection() returns CGRect.null (infinite coordinates) when
the crop guide frame and container bounds don't overlap during a pan
gesture. Setting infinite values as NSLayoutConstraint constants
triggers NSInternalInconsistencyException.
Two layers of defense:
1. updateMaximumRect(): skip update when intersection is null, keeping
the previous valid maximumRect so constraints use stale-but-safe
values until the next valid frame.
2. activate{Left,Right,Top,Bottom}MaxConstraint(): guard maximumRect
and superview instead of force-unwrapping, so a nil maximumRect
(e.g. null intersection on gesture begin) gracefully skips
constraint activation instead of crashing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #282
CGRect.intersection()returns.null(infinite coords) when the crop guide frame and container bounds don't overlap during a fast pan gesture. Settinginfas a constraint constant crashes withNSInternalInconsistencyException.Changes
updateMaximumRect()— bail out when intersection is null; keep the previousmaximumRectso constraints stay on the last valid values until the next good frame.activate{Left,Right,Top,Bottom}MaxConstraint()— replacemaximumRect!/superview!force-unwraps withguard letso a nilmaximumRect(if the first intersection on.beganis somehow null) skips constraint activation instead of crashing.