NSView draws unwanted tiling "seam" lines when zoomed

I have a large custom NSView subclass that's set as an NSScrollView's documentView. This view achieves zooming in the standard AppKit way, by having a bounds size that's some factor of the frame size, eg: frame.size.width = bounds.size.width * 2.0. This has worked just fine for years.

The problem is that on modern versions of macOS (eg: Catalina), for certain zoom factors, there are "seams" that show up during drawing. The seams are fine lines that show a view's background color (or stale content from a prior drawing pass). The seams are always aligned in neat rectangular patterns, which tipped me off that macOS is doing some kind of tiling.

After poking around I see that my view is assigned a CALayer, despite never opting-in via setWantsLayer or anything like that. This implicit layer backing seems to be expected on current versions of macOS, but it's definitely the cause of my problem. I can see that my view is assigned a layer like:

_NSViewBackingLayer → sublayers: _NSTiledLayer

If I increase the tileSize property of this automatically generated layer (eg: from 512x512 to 2048x2048), I can decrease the visual frequency of the problem. But this is naturally a hack, and not a complete solution. The seams still occur, just less often.

Can I somehow opt my view out of implicit layer backing? Is there a more modern way to implement zoom now that everything is using layers?

I think everything is layers now. The "modern" way to do this would be to use Swift UI. Can you try a little demo in Swift UI to see if you get the same effect?

What you describe is pretty common when doing tiled layers on purpose. You have to fudge the bounds of each tile a bit so it overlaps the other tiles. Perhaps Apple isn't doing that. On the bright side, it is nice to see Apple suffer from the same bugs.

I think what causes this is Apple trying to efficiently manage the the zooming by only rendering the parts of the view that are necessary. Those "standard AppKit" ways are likely to break because AppKit is going away. Have you tried using a magnification factor instead?
@Etresoft Thank you for the reply!

SwiftUI is a non-starter. This is a mature Mac-only app built using AppKit. The view in question isn't a trivial widget, but rather a complicated and dynamic view hierarchy that isn't suitable to be implemented in SwiftUI– at least for now. We'll see what happens as SwiftUI develops.

Thanks for suggesting the use of a magnification factor. I actually forgot about -[NSScrollView magnification] because this is older code that predates that property. Unfortunately the results are the same.

Even in a simple test project that uses NSScrollView's magnification factor the errant seam lines occur. The bug manifests even for zoom factors that seem relatively benign, eg: 1.5x zoom. Oh well, I guess this is just an unavoidable drawing bug of macOS. I'll see about sending in a feedback report to Apple.
Are you using a Retina display? Most drawing logic assumes a retina display. You will often see graphics artifacts on non-retina display.

Maybe use a DTS ticket instead of just filling a bug.
I'm reproducing the bug on an attached Dell 4K monitor. The seams show whether the display is set to the default resolution or scaled. But regardless I've had dozens of customers report this issue, and we can't very well tell them all to buy new Retina monitors!

A DTS ticket may be a good idea, but my sense right now is that this isn't anything that can be worked around.
NSView draws unwanted tiling "seam" lines when zoomed
 
 
Q