fix(ios): avoid zero size crash when using UIGraphics api in debug mode

This commit is contained in:
wwwcg
2024-05-10 16:50:03 +08:00
committed by wwwcg
parent 0aa7901e3e
commit 48573efbcf
2 changed files with 11 additions and 2 deletions
+5
View File
@@ -642,6 +642,11 @@ void HippyBoarderColorsRelease(HippyBorderColors c) {
return YES;
}
else if (self.backgroundImageUrl) {
CGSize size = theFrame.size;
if (0 >= size.width || 0 >= size.height) {
contentBlock(nil);
return YES;
}
CGFloat backgroundPositionX = self.backgroundPositionX;
CGFloat backgroundPositionY = self.backgroundPositionY;
HippyBackgroundImageCacheManager *weakBackgroundCacheManager = [self backgroundCachemanager];
@@ -110,6 +110,7 @@ NSString *const HippyPageImageFormatJPEG = @"jpeg";
if (!rootView) {
HippyLogWarn(@"PageModel, screen cast, root view is nil");
completion(@{});
return;
}
CGFloat viewWidth = rootView.frame.size.width;
CGFloat viewHeight = rootView.frame.size.height;
@@ -118,6 +119,10 @@ NSString *const HippyPageImageFormatJPEG = @"jpeg";
CGFloat scaleX = self.maxSize.width / viewWidth;
CGFloat scaleY = self.maxSize.height / viewHeight;
scale = MIN(scaleX, scaleY);
} else {
HippyLogWarn(@"PageModel, screen cast, root view size is 0");
completion(@{});
return;
}
// root view snapshot
UIGraphicsBeginImageContextWithOptions(rootView.frame.size, NO, scale);
@@ -141,8 +146,7 @@ NSString *const HippyPageImageFormatJPEG = @"jpeg";
resultJSON[HippyPageKeySessionId] = @(timestamp);
self.lastTimestamp = timestamp;
completion(resultJSON);
}
else {
} else {
completion(@{});
}
});