-[NSWindow invalidateShadow] has stopped working in 10.12
| Originator: | markus.stange | ||
| Number: | rdar://27121204 | Date Originated: | 2016-06-30 |
| Status: | Open | Resolved: | |
| Product: | OS X | Product Version: | 10.12 Beta (16A201w) |
| Classification: | Serious Bug | Reproducible: | Always |
Summary:
Calling -[NSWindow invalidateShadow] no longer updates the shadow shape in a transparent borderless NSWindow with a shadow. The stale shadow from the first paint remains.
Steps to Reproduce:
1. Download the attached file and save it as main.m.
2. Compile and run it with clang++ main.m -framework Cocoa -o test && ./test
3. Wait for two seconds.
Expected Results:
There should be a blue circle with a shadow around it.
Actual Results:
The blue circle doesn't have a shadow. Instead, there is a shadow in the place where there was a red circle. invalidateShadow failed to update the shadow.
Version:
10.12 Beta (16A201w)
Notes:
Configuration:
Attachments:
'main.m' was successfully uploaded.
Contents of main.m reproduced here for convenience:
/**
* Save as main.m.
* Compile and run using: clang++ main.m -framework Cocoa -o test && ./test
*
* This program creates a borderless window with a transparent background, and a shadow.
* It draws a red circle into it. After two seconds, it repaints, and draws a blue circle
* in a different location. Then it calls -[NSWindow invalidateShadow] so that the shadow
* is updated to be around the blue circle instead of around the red circle.
*
* However, on 10.12 Beta (16A201w), invalidateShadow has no effect and the stale shadow remains.
**/
#import <Cocoa/Cocoa.h>
@interface TestView: NSView
{
bool _firstDraw;
}
@end
@implementation TestView
- (id)initWithFrame:(NSRect)aFrame
{
if (self = [super initWithFrame:aFrame]) {
_firstDraw = YES;
}
return self;
}
- (void)drawRect:(NSRect)rect
{
if (_firstDraw) {
// Draw a red circle in the bottom left corner.
NSRect r = NSMakeRect(10, 10, 50, 50);
NSBezierPath* circlePath = [NSBezierPath bezierPath];
[circlePath appendBezierPathWithOvalInRect: r];
[[NSColor redColor] set];
[circlePath fill];
_firstDraw = NO;
// trigger second draw.
[self performSelector:@selector(invalidate) withObject:nil afterDelay:2.0];
} else {
// Draw a blue circle further up and to the right from the right circle.
NSRect r = NSMakeRect(100, 70, 50, 50);
NSBezierPath* circlePath = [NSBezierPath bezierPath];
[circlePath appendBezierPathWithOvalInRect: r];
[[NSColor blueColor] set];
[circlePath fill];
// Invalidate the window shadow.
[[self window] performSelector:@selector(invalidateShadow) withObject:nil afterDelay:0.0];
}
}
- (void)invalidate
{
[self setNeedsDisplay:YES];
}
- (void)mouseUp:(NSEvent*)event
{
// Shut down on double click.
if ([event clickCount] >= 2) {
[NSApp terminate:self];
}
}
@end
int
main (int argc, char **argv)
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
[NSApplication sharedApplication];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
int style = NSBorderlessWindowMask;
NSRect contentRect = NSMakeRect(400, 300, 300, 400);
NSWindow* window = [[NSWindow alloc] initWithContentRect:contentRect
styleMask:style
backing:NSBackingStoreBuffered
defer:NO];
[window setHasShadow:YES];
[window setBackgroundColor:[NSColor clearColor]];
NSView* view = [[TestView alloc] initWithFrame:NSMakeRect(0, 0, contentRect.size.width, contentRect.size.height)];
[window setContentView:view];
[NSApp activateIgnoringOtherApps:YES];
[window makeKeyAndOrderFront:window];
[NSApp run];
[pool release];
return 0;
}
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
This bug has been fixed in Beta 4.