We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1065 - osx: uncaught exception NSInternalInconsistencyException, error creating CGSWindow
Summary: osx: uncaught exception NSInternalInconsistencyException, error creating CGSW...
Status: RESOLVED INVALID
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 1.2.14
Hardware: Other Mac OS X 10.6
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-20 13:22 UTC by Marc L
Modified: 2010-12-21 03:11 UTC (History)
1 user (show)

See Also:


Attachments
gdb backtrace (2.67 KB, application/octet-stream)
2010-10-20 13:22 UTC, Marc L
Details
Fixed version of submitted file (343 bytes, text/plain)
2010-12-20 14:26 UTC, Toomas Laasik
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marc L 2010-10-20 13:22:52 UTC
Created attachment 540 [details]
gdb backtrace

When trying a very simple SDL test program it fails with a traceback saying:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error (1002) creating CGSWindow'
*** call stack here
terminate called after throwing an instance of 'NSException'

I've attached the gdb backtrace, and the test code is the following:

/*
 * Built with
 * cc -g -ggdb3 -fno-inline -o test_sdl test_sdl.c -I/opt/local/include -L/opt/local/lib -lsdl -lsdlmain
 */
void run();

int main(int argc, char *argv[]) {
    run();
}

#include <SDL/SDL.h>

void run()
{
    SDL_Init(SDL_INIT_VIDEO);
    SDL_SetVideoMode(640,480,0,SDL_OPENGL);
}
Comment 1 Toomas Laasik 2010-12-20 14:26:45 UTC
Created attachment 551 [details]
Fixed version of submitted file
Comment 2 Toomas Laasik 2010-12-21 03:11:05 UTC
I think that this is technically not a bug, but just the way how SDL works.

To fix the submitted case you have to do 2 things:
  - #include <SDL/SDL.h> before main
  - add linker flag -Wl,-framework,Cocoa
  - (it is a also good idea to exit gracefully with SDL_Quit)

SDL uses C preprocessor to redefine keyword "main". This is how it grabs control before any of your code executes and also makes program entry point cross-platform (eg windows had WinMain for graphical apps, but you still use main in SDL as entry point). The redefined main on OSX runs code that prepares native Cocoa framework for creating window (a bunch of NS... calls). If you manage to put main before you include SDL.h, then you'll get those "NS not properly initialized"-type errors.