From f8d19414d5338b4f44f8a8f005da0cffca567dd1 Mon Sep 17 00:00:00 2001 From: James Magahern Date: Fri, 14 Apr 2023 19:37:31 -0700 Subject: [PATCH] Avoid generating zero size bitmaps --- App/Common UI/GradientView.swift | 3 ++- App/Titlebar and URL Bar/URLBar.swift | 3 ++- App/Web Process Bundle Bridge/SBRScriptPolicy.m | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/App/Common UI/GradientView.swift b/App/Common UI/GradientView.swift index 2eede82..15fcf4a 100644 --- a/App/Common UI/GradientView.swift +++ b/App/Common UI/GradientView.swift @@ -31,8 +31,9 @@ class GradientView: UIImageView } private func gradientImage(forSize size: CGSize) -> UIImage? { - var image: UIImage? = nil + guard size != .zero else { return nil } + var image: UIImage? = nil UIGraphicsBeginImageContext(size) if let context = UIGraphicsGetCurrentContext() { let gradientColorsArray = self.colors.map { $0.cgColor } diff --git a/App/Titlebar and URL Bar/URLBar.swift b/App/Titlebar and URL Bar/URLBar.swift index 9e8a3a3..cf60064 100644 --- a/App/Titlebar and URL Bar/URLBar.swift +++ b/App/Titlebar and URL Bar/URLBar.swift @@ -281,8 +281,9 @@ class URLBar: ReliefButton } private func fadeBackgroundImageForSize(_ size: CGSize, cutoffLocation: CGFloat) -> UIImage? { - var image: UIImage? = nil + guard size != .zero else { return nil } + var image: UIImage? = nil UIGraphicsBeginImageContext(CGSize(width: size.width, height: 1.0)) if let context = UIGraphicsGetCurrentContext() { let gradientColorsArray = [ diff --git a/App/Web Process Bundle Bridge/SBRScriptPolicy.m b/App/Web Process Bundle Bridge/SBRScriptPolicy.m index c45e857..b3d9237 100644 --- a/App/Web Process Bundle Bridge/SBRScriptPolicy.m +++ b/App/Web Process Bundle Bridge/SBRScriptPolicy.m @@ -77,6 +77,10 @@ static CGFloat RoundToScale(CGFloat v, CGFloat s) { + (UIImage *)iconRepresentationForPolicyType:(SBRScriptOriginPolicyType)policyType withConfiguration:(nonnull SBRScriptPolicyIconConfiguration *)configuration { const CGSize size = [configuration size]; + if (CGSizeEqualToSize(size, CGSizeZero)) { + return nil; + } + UIFont *font = [UIFont boldSystemFontOfSize:size.height - 2]; NSDictionary *attrs = @{ NSFontAttributeName : font,