I am creating a Cocoa OpenGL game in Xcode, which I wish to at some point distribute on the Mac App store. I’m unsure what to do when my application encounters a fatal error, namely being unable to create a pixel format or OpenGL context. I think I should display some message saying what happened, perhaps giving the user a form to enter a quick comment and have it sent to me (how would I do this?), and then terminate. But what would be the best way to do this?
…
NSOpenGLPixelFormatAttribute attribs[] = {
…
NSOpenGLPFAAccelerated, // Hardware acceleration
NSOpenGLPFADoubleBuffer, // Double buffering
NSOpenGLPFAColorSize, 320, // *** THIS IS FOR TESTING FAILURE ***
0
};
// Create pixel format
pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
if (!pixelFormat) {
//////////////////////////////FATAL ERROR//////////////////////////////
}
// Create OpenGL context
openGLContext = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil];
if (!openGLContext) {
//////////////////////////////FATAL ERROR//////////////////////////////
}
…
Notice I’ve requested a color size of 320 simply to test what will happen in this unlikely case.
I’ve looked into NSAlert but it seems to be more suited for warning messages, even when the style is set to NSCriticalAlertStyle. And I think afterwards I should quit with [NSApp terminate:nil] but I’m unsure. What should I do in these cases, to be consistent other apps and to conform to the Apple way of doing such a thing?
Note that this only happens on startup.
I don’t think you should ask the user for info. You should probably write state to disk and then offer to send the crash report on next startup. Your data should record what the user’s last N actions were, etc. Asking the user for info is irritating to the user, and probably won’t give you the real info you need.