-
Notifications
You must be signed in to change notification settings - Fork 251
Open
Labels
Description
π Deprecated API Usage: UIGraphicsBeginImageContextWithOptions
may cause crash in low-memory
Hi, I noticed that this library is using the deprecated UIGraphicsBeginImageContextWithOptions
API in the following line:
SDWebImageSwiftUI/SDWebImageSwiftUI/Classes/WebImage.swift
Lines 211 to 214 in ea24105
UIGraphicsBeginImageContextWithOptions(image.size, false, scale) | |
image.draw(at: .zero) | |
cgImage = UIGraphicsGetImageFromCurrentImageContext()?.cgImage | |
UIGraphicsEndImageContext() |
Apple has marked this API as deprecated (with version 100000
) and recommends replacing it with UIGraphicsImageRenderer
.
π₯ Crash Context (low-memory device)
In some cases, especially on devices with low memory, the following crash can occur:
Fatal Exception: NSInternalInconsistencyException
UIGraphicsBeginImageContext() failed to allocate CGBitampContext: size={...}, scale=..., bitmapInfo=...
Use UIGraphicsImageRenderer to avoid this assert.
π Deprecation Info
@available(iOS, introduced: 4.0, deprecated: 100000, message: "Replace usage of UIGraphicsBeginImageContextWithOptions with UIGraphicsImageRenderer.")
public func UIGraphicsBeginImageContextWithOptions(_ size: CGSize, _ opaque: Bool, _ scale: CGFloat)
@available(iOS, introduced: 2.0, deprecated: 100000, message: "Replace usage of UIGraphicsBeginImageContext with UIGraphicsImageRenderer.")
public func UIGraphicsBeginImageContext(_ size: CGSize)
@available(iOS, introduced: 2.0, deprecated: 100000, message: "Replace usage of UIGraphicsGetImageFromCurrentImageContext with UIGraphicsImageRendererContext.currentImage.")
public func UIGraphicsGetImageFromCurrentImageContext() -> UIImage?
@available(iOS, introduced: 2.0, deprecated: 100000, message: "UIGraphicsEndImageContext should only be used alongside UIGraphicsBeginImageContext[WithOptions].")
public func UIGraphicsEndImageContext()
β Kingfisher Reference
For reference, this has already been fixed in Kingfisher in the following PR:
π‘ Suggestion
Would you consider updating SDWebImageSwiftUI to use UIGraphicsImageRenderer
instead?
Itβs safer and preferred in modern iOS development, and avoids low-memory crashes.
Thanks for your great work on this library! π