Skip to content

Commit

Permalink
skip drawing if drawable size is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
ghugues committed Oct 6, 2024
1 parent ef6c7bb commit d1b958c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Source/Renderer/rive_renderer_view.mm
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,15 @@ - (bool)isPaused

- (void)drawInRect:(CGRect)rect withCompletion:(_Nullable MTLCommandBufferHandler)completionHandler
{
if (CGRectGetWidth(rect) == 0 || CGRectGetHeight(rect) == 0)
CGSize drawableSize = self.drawableSize;
CGFloat width = drawableSize.width;
CGFloat height = drawableSize.height;
NSInteger maxSize = _renderContext.maxTextureSize;

// If `rect` has a zero size, `drawableSize` may have a `nan` size.
// If a parent view has a very small scale transform, `drawableSize` may exceed the maximum texture size.
// If a parent view has a zero scale transform, `drawableSize` may have an infinite size.
if (width == 0.0 || height == 0.0 || isnan(width) || isnan(height) || width > maxSize || height > maxSize)
{
return;
}
Expand All @@ -179,7 +187,7 @@ - (void)drawInRect:(CGRect)rect withCompletion:(_Nullable MTLCommandBufferHandle
if (_renderer != nil)
{
_renderer->save();
[self drawRive:rect size:self.drawableSize];
[self drawRive:rect size:drawableSize];
_renderer->restore();
}
[_renderContext endFrame:self withCompletion:completionHandler];
Expand Down

0 comments on commit d1b958c

Please sign in to comment.