Protect against [window screen] returning nil.

This commit is contained in:
fredkiefer 2017-10-05 23:05:28 +02:00
parent 020d3fa183
commit e3d51643ca
3 changed files with 20 additions and 3 deletions

View file

@ -1,3 +1,10 @@
2017-10-05 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSMenu.m (-isPartlyOffScreen): Protect agains window or
screen being nil.
* Source/NSWindow.m (-_screenForFrame:): Try not to return nil, as
other code uses the result without checks.
2017-10-01 Ivan Vucica <ivan@vucica.net>
* Documentation/ReleaseNotes.gsdoc:

View file

@ -1545,7 +1545,7 @@ static BOOL menuBarVisible = YES;
[_view sizeToFit];
menuFrame = [_view frame];
// Main
oldWindowFrame = [_aWindow frame];
newWindowFrame = [NSWindow frameRectForContentRect: menuFrame
@ -1855,7 +1855,15 @@ static BOOL menuBarVisible = YES;
NSWindow *window;
window = [self window];
return !NSContainsRect([[window screen] visibleFrame], [window frame]);
if ((nil != window) && (nil != [window screen]))
{
return !NSContainsRect([[window screen] visibleFrame], [window frame]);
}
else
{
NSLog(@"Menu has no window %@ or screen %@", window, [window screen]);
return YES;
}
}
- (void) _performMenuClose: (id)sender

View file

@ -389,7 +389,9 @@ has blocked and waited for events.
*/
- (NSScreen *) _screenForFrame: (NSRect)frame
{
CGFloat largest = 0.0;
// FIXME: We always return the first screen, if there is no overlap.
// Other code relies on [window screen] not returning nil.
CGFloat largest = -1.0;
NSArray *screens = [NSScreen screens];
NSInteger index = 0;
NSScreen *theScreen = nil;