macOS Tahoe: NSView -cacheDisplayInRect:toBitmapImageRep: Doesn't Work Unless View is Added to Window

Previously I was able to "snapshot" view that were not part of any window hierarchy using the following:

  NSImage *buttonImage = [NSImage imageWithSystemSymbolName:@"49.circle.fill" accessibilityDescription:nil];
 NSButton *aButton = [NSButton buttonWithImage:buttonImage target:nil action:nil]; 
[aButton sizeToFit];

NSBitmapImageRep *rep = [aButton bitmapImageRepForCachingDisplayInRect:aButton.bounds];
    if (rep == nil) {
        NSLog(@"Failed to get bitmap image rep."); 
         return;
    }

  [aButton cacheDisplayInRect:aButton.bounds toBitmapImageRep:rep];

  NSData *tiffData = rep.TIFFRepresentation;
  NSImage *snapShotOfImage = [[NSImage alloc]initWithData:tiffData];

Now on macOS Tahoe I get a non nil image, but the image is blank.

However if I add aButton NSWindow's view hiearchy just before the call to -cacheDisplayInRect:toBitmapImageRep: I do get a proper image.

Is this behavior intended or is this considered a bug? Is it documented anywhere that a view must be in a NSWindow for -cacheDisplayInRect:toBitmapImageRep: to work? Thanks

I filed FB20272813

macOS Tahoe: NSView -cacheDisplayInRect:toBitmapImageRep: Doesn't Work Unless View is Added to Window
 
 
Q