You’re now watching this thread. If you’ve opted in to email or web notifications, you’ll be notified when there’s activity. Click again to stop watching or visit your profile to manage watched threads and notifications.
You’ve stopped watching this thread and will no longer receive emails or web notifications when there’s activity. Click again to start watching.
Create a new standard iOS project and add a Widget extension to it.
Download an SVG from here: https://pixabay.com/vectors/flourish-decorative-ornamental-3166119/
Add the SVG asset into Assets.xcassets.
Replace the line Text(entry.date, style: .time) with Image("flourish-3166119").frame(width: 20).
When running the extension, I get Thread 1: EXC_RESOURCE RESOURCE_TYPE_MEMORY (limit=30 MB, unused=0x0). Notice that the asset is only 8k but something in the rendering of the SVG into bitmap cause a memory spike.
I tested this with Xcode 13.0, iOS 14.4.1 Xs MAX device.
Is there a way to overcome this, or should I dump SVG and pre render the images for x2 and x3 scale factors and call it a day?
Edit: Just to clarify, the issue happens with only 1 entry as well. I attached the full source for reference.
//
// WidgetCrashTestWidget.swift
// WidgetCrashTestWidget
//
// Created by Artium Nihamkin on 26/09/2021.
//
import WidgetKit
import SwiftUI
struct Provider: TimelineProvider {
func placeholder(in context: Context) -> SimpleEntry {
SimpleEntry(date: Date())
}
func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) {
let entry = SimpleEntry(date: Date())
completion(entry)
}
func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
var entries: [SimpleEntry] = []
// Generate a timeline consisting of five entries an hour apart, starting from the current date.
let currentDate = Date()
for hourOffset in 0 ..< 0 {
let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)!
let entry = SimpleEntry(date: entryDate)
entries.append(entry)
}
let timeline = Timeline(entries: entries, policy: .atEnd)
completion(timeline)
}
}
struct SimpleEntry: TimelineEntry {
let date: Date
}
struct WidgetCrashTestWidgetEntryView : View {
var entry: Provider.Entry
var body: some View {
Image("flourish-3166119")
.frame(width: 20)
}
}
@main
struct WidgetCrashTestWidget: Widget {
let kind: String = "WidgetCrashTestWidget"
var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: Provider()) { entry in
WidgetCrashTestWidgetEntryView(entry: entry)
}
.configurationDisplayName("My Widget")
.description("This is an example widget.")
}
}
struct WidgetCrashTestWidget_Previews: PreviewProvider {
static var previews: some View {
WidgetCrashTestWidgetEntryView(entry: SimpleEntry(date: Date()))
.previewContext(WidgetPreviewContext(family: .systemSmall))
}
}