Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

osx: uncaught exception NSInternalInconsistencyException, error creating CGSWindow #601

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 0 comments
Labels
invalid This doesn't seem right

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: 1.2.14
Reported for operating system, platform: Mac OS X 10.6, Other

Comments on the original bug report:

On 2010-10-20 13:22:52 +0000, Marc L wrote:

Created attachment 540
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);
}

On 2010-12-20 14:26:45 +0000, Toomas Laasik wrote:

Created attachment 551
Fixed version of submitted file

On 2010-12-21 03:11:05 +0000, Toomas Laasik wrote:

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.

@SDLBugzilla SDLBugzilla added bug invalid This doesn't seem right labels Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

1 participant