From 364f3a76392f7bf0026f8c0627e1c813dc1fda15 Mon Sep 17 00:00:00 2001 From: Chris Campbell Date: Fri, 30 Apr 2021 00:52:15 -0400 Subject: [PATCH] Prevent infinite loop in DetailWebView.setFrameSize() DetailWebView.setFrameSize() calls bigSurOffsetFix(), which changes the window's frame, which ultimately calls setFrameSize() again (which calls bigSurOffsetFix(), etc). In practice, this isn't causing an infinite loop (I think NSWindow.setFrame(_:display:) is smart enough to prevent reentrancy) but it's still dangerous to have such a glaring logic error in the code. --- Mac/MainWindow/Detail/DetailWebView.swift | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Mac/MainWindow/Detail/DetailWebView.swift b/Mac/MainWindow/Detail/DetailWebView.swift index 146708f2c..a6e4a5c45 100644 --- a/Mac/MainWindow/Detail/DetailWebView.swift +++ b/Mac/MainWindow/Detail/DetailWebView.swift @@ -58,11 +58,13 @@ final class DetailWebView: WKWebView { override func setFrameSize(_ newSize: NSSize) { super.setFrameSize(newSize) - if (!self.inLiveResize) { + if (!inLiveResize) { bigSurOffsetFix() } } + private var inBigSurOffsetFix = false + private func bigSurOffsetFix() { /* On macOS 11, when a user exits full screen @@ -76,6 +78,17 @@ final class DetailWebView: WKWebView { guard var frame = window?.frame else { return } + + guard !inBigSurOffsetFix else { + return + } + + inBigSurOffsetFix = true + + defer { + inBigSurOffsetFix = false + } + frame.size = NSSize(width: window!.frame.width, height: window!.frame.height - 1) window!.setFrame(frame, display: false) frame.size = NSSize(width: window!.frame.width, height: window!.frame.height + 1)