Skip to content

Commit

Permalink
Catch Invalid Layer Bounds in a Nonfatal Assertion #trivial (TextureG…
Browse files Browse the repository at this point in the history
…roup#308)

* Add a non-fatal assertion for setting invalid layer bounds.

* Update message
  • Loading branch information
Adlai-Holler authored and bernieperez committed Apr 25, 2018
1 parent 6a654e6 commit 2ae281a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
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

0 comments on commit 2ae281a

Please sign in to comment.