Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch Invalid Layer Bounds in a Nonfatal Assertion #trivial #308

Merged
merged 2 commits into from
May 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Source/Base/ASAssert.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@
#define ASDisplayNodeErrorDomain @"ASDisplayNodeErrorDomain"
#define ASDisplayNodeNonFatalErrorCode 1

#define ASDisplayNodeAssertNonFatal(condition, desc, ...) \
ASDisplayNodeAssert(condition, desc, ##__VA_ARGS__); \
if (condition == NO) { \
/// Returns YES if assertion passed, NO otherwise.
#define ASDisplayNodeAssertNonFatal(condition, desc, ...) ({ \
BOOL __evaluated = condition; \
if (__evaluated == NO) { \
ASDisplayNodeFailAssert(desc, ##__VA_ARGS__); \
ASDisplayNodeNonFatalErrorBlock block = [ASDisplayNode nonFatalErrorBlock]; \
if (block != nil) { \
NSDictionary *userInfo = nil; \
Expand All @@ -81,4 +83,6 @@
NSError *error = [NSError errorWithDomain:ASDisplayNodeErrorDomain code:ASDisplayNodeNonFatalErrorCode userInfo:userInfo]; \
block(error); \
} \
}
} \
__evaluated; \
}) \
4 changes: 4 additions & 0 deletions Source/Details/_ASDisplayLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ - (void)setDisplaySuspended:(BOOL)displaySuspended

- (void)setBounds:(CGRect)bounds
{
BOOL valid = ASDisplayNodeAssertNonFatal(ASIsCGRectValidForLayout(bounds), @"Caught attempt to set invalid bounds %@ on %@.", NSStringFromCGRect(bounds), self);
if (!valid) {
return;
}
if (_delegateFlags.delegateDidChangeBounds) {
CGRect oldBounds = self.bounds;
[super setBounds:bounds];
Expand Down