Ok, this is a question about long-deprecated code. As mentioned previously, I'm resurrecting an old Objective C Mac app written with OpenGL, to buy me some time to rewrite it in Swift/SwiftUI and Metal.
The background:
The program is a fractal rendering app called FractalWorks, and it actually sold pretty well in the App Store back in the day, and some FractalWorks images got published in a few different publications.
One was the book "Fractal 3D Magic". I created about half of the FractalWorks images in that book, and a friend of mine named Fernando created the other half. He's got limited means, and so has a very old Mac that can't run recent versions of macOS. He's stuck on 10.13.
I asked him to beta test the new version of FractalWorks, and he reported the app crashes when he tries to display a 3D view (which is where I use NSOpenGLView objects.) It crashes every time he opens a 3D window.
For frustrating reasons I don't want to get into, I haven't been able to get Apple to approve a TestFlight build, so I've been making a "direct distribution" build that Apple notarizes. That makes getting symbolicated crash reports a lot harder, so it took me a long time to find out where the crash was occurring.
The crash:
It's a segmentation fault. After a pretty big struggle, I was able to learn the line of code that was crashing. It was my code to create an NSOpenGLPixelFormat:
NSOpenGLPixelFormat * pf = [BasicOpenGLView basicPixelFormat];
I had added a line above that to get the images to scale correctly on my Retina M2 Mac:
self.wantsBestResolutionOpenGLSurface = true;
It turns out setting wantsBestResolutionOpenGLSurface to true causes the line that calls basicPixelFormat to crash on Macs running 10.13.
Why would that be? I was able to prevent the crash by wrapping the offending line in an OS version check:
if (@available(macOS 10.15, *)) {
self.wantsBestResolutionOpenGLSurface = true;
}
NSOpenGLPixelFormat * pf = [BasicOpenGLView basicPixelFormat];
But I'd love to understand why that causes a crash. (And I'm fairly certain that there are Retina Macs that can't advance past 10.13, so I'd like a solution that works in older OS versions.)