Skip to content

Commit

Permalink
Fix leak (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahsmartin authored Aug 23, 2024
1 parent 08a5806 commit 22cf568
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Sources/SnapshotPreviewsCore/AppKitRenderingStrategy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ public class AppKitRenderingStrategy: RenderingStrategy {
}
let vc = AppKitContainer(rootView: wrappedView)
vc.setupView(layout: preview.layout)
vc.rendered = { mode, precision, accessibilityEnabled in
// Reset the window size to default before adding the new view controller
window.contentViewController = NSViewController()
window.setContentSize(AppKitContainer.defaultSize)
window.contentViewController = vc
vc.rendered = { [weak vc] mode, precision, accessibilityEnabled in
DispatchQueue.main.async {
let image = vc.view.snapshot()
let image = vc?.view.snapshot()
completion(
SnapshotResult(
image: image != nil ? .success(image!) : .failure(SwiftUIRenderingError.renderingError),
Expand All @@ -55,10 +59,6 @@ public class AppKitRenderingStrategy: RenderingStrategy {
colorScheme: _colorScheme))
}
}
// Reset the window size to default before adding the new view controller
window.contentViewController = NSViewController()
window.setContentSize(AppKitContainer.defaultSize)
window.contentViewController = vc
}
}

Expand Down

0 comments on commit 22cf568

Please sign in to comment.