Skip to content

Commit 7af7aa9

Browse files
committed
Another workaround for another macOS Tahoe bug
Dont redraw an OSWindow during a resize event if the resize event is accompanied by a screen change as it causes a crash in macOS OpenGL driver. Fixes #8983
1 parent 24b31d9 commit 7af7aa9

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

docs/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ Detailed list of changes
179179
- macOS: Workaround for bug in macOS Tahoe that caused closed OS Windows to
180180
remain as invisible rectangles that intercept mouse events (:iss:`8952`)
181181

182+
- macOS: Workaround for bug in macOS Tahoe that caused OS Windows that are
183+
fullscreen on a monitor that is disconnected while macOS is asleep to crash kitty (:iss:`8983`)
184+
185+
182186
0.42.2 [2025-07-16]
183187
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
184188

glfw/cocoa_window.m

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ static void releaseMonitor(_GLFWwindow* window)
521521
@interface GLFWWindowDelegate : NSObject
522522
{
523523
_GLFWwindow* window;
524+
NSArray<NSDictionary *> *_lastScreenStates;
524525
}
525526

526527
- (instancetype)initWithGlfwWindow:(_GLFWwindow *)initWindow;
@@ -533,12 +534,26 @@ @implementation GLFWWindowDelegate
533534
- (instancetype)initWithGlfwWindow:(_GLFWwindow *)initWindow
534535
{
535536
self = [super init];
536-
if (self != nil)
537+
if (self != nil) {
537538
window = initWindow;
538-
539+
_lastScreenStates = [self captureScreenStates];
540+
}
539541
return self;
540542
}
541543

544+
- (NSArray<NSDictionary *> *)captureScreenStates {
545+
NSMutableArray *states = [NSMutableArray array];
546+
for (NSScreen *screen in [NSScreen screens]) {
547+
// Use the screen's deviceDescription, which contains a stable ID.
548+
[states addObject:screen.deviceDescription];
549+
}
550+
return [states copy];
551+
}
552+
553+
- (void)cleanup {
554+
[_lastScreenStates release]; _lastScreenStates = nil;
555+
}
556+
542557
- (BOOL)windowShouldClose:(id)sender
543558
{
544559
(void)sender;
@@ -549,6 +564,16 @@ - (BOOL)windowShouldClose:(id)sender
549564
- (void)windowDidResize:(NSNotification *)notification
550565
{
551566
(void)notification;
567+
NSArray<NSDictionary *> *currentScreenStates = [self captureScreenStates];
568+
const bool is_screen_change = ![_lastScreenStates isEqualToArray:currentScreenStates];
569+
debug_rendering("windowDidResize() called, is_screen_change: %d\n", is_screen_change);
570+
if (is_screen_change) {
571+
// This resize likely happened because a screen was added, removed, or changed resolution.
572+
[_lastScreenStates release];
573+
_lastScreenStates = [currentScreenStates retain];
574+
}
575+
[currentScreenStates release];
576+
552577
if (window->context.client != GLFW_NO_API)
553578
[window->context.nsgl.object update];
554579

@@ -580,7 +605,10 @@ - (void)windowDidResize:(NSNotification *)notification
580605
window->ns.height = (int)contentRect.size.height;
581606
_glfwInputWindowSize(window, (int)contentRect.size.width, (int)contentRect.size.height);
582607
}
583-
if (window->ns.resizeCallback) window->ns.resizeCallback((GLFWwindow*)window);
608+
// Because of a bug in macOS Tahoe we cannot redraw the window in response
609+
// to a resize event that was caused by a screen change as the OpenGL
610+
// context is not ready yet. See: https://github.com/kovidgoyal/kitty/issues/8983
611+
if (window->ns.resizeCallback && !is_screen_change) window->ns.resizeCallback((GLFWwindow*)window);
584612
}
585613

586614
- (void)windowDidMove:(NSNotification *)notification
@@ -1913,6 +1941,7 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
19131941
window->context.destroy(window);
19141942

19151943
[window->ns.object setDelegate:nil];
1944+
[window->ns.delegate cleanup];
19161945
[window->ns.delegate release];
19171946
window->ns.delegate = nil;
19181947

0 commit comments

Comments
 (0)