Permalink
Browse files

call [NSApplication sharedApplication] before SDL_Init(), otherwise t…

…he app will crash when SDL_SetVideoMode() is called
  • Loading branch information...
Richard Mazorodze
Richard Mazorodze committed Feb 27, 2012
1 parent 3103ce2 commit 709aa22b76cd7f16dcad73f6a65e4d940e1f0a5a
Showing with 12 additions and 3 deletions.
  1. +12 −3 src/sdl.cc
View
@@ -1,11 +1,21 @@
-#include "sdl.h"
-using namespace v8;
+#ifdef __APPLE__
+#include <objc/objc.h>
+#include <objc/objc-runtime.h>
+#endif
+#include "SDL.h"
+using namespace v8;
extern "C" void
init(Handle<Object> target)
{
+#ifdef __APPLE__
+ // on the mac it is necessary to create to call [NSApplication sharedApplication]
+ // before we can create a rendering window
+ objc_msgSend(objc_lookUpClass("NSApplication"), sel_getUid("sharedApplication"));
+#endif
+
NODE_SET_METHOD(target, "init", sdl::Init);
NODE_SET_METHOD(target, "initSubSystem", sdl::InitSubSystem);
NODE_SET_METHOD(target, "quit", sdl::Quit);
@@ -107,7 +117,6 @@ init(Handle<Object> target)
GL->Set(String::New("ACCUM_GREEN_SIZE"), Number::New(SDL_GL_ACCUM_GREEN_SIZE));
GL->Set(String::New("ACCUM_BLUE_SIZE"), Number::New(SDL_GL_ACCUM_BLUE_SIZE));
GL->Set(String::New("ACCUM_ALPHA_SIZE"), Number::New(SDL_GL_ACCUM_ALPHA_SIZE));
-
}
////////////////////////////////////////////////////////////////////////////////

5 comments on commit 709aa22

@TooTallNate

This comment has been minimized.

Show comment Hide comment
@TooTallNate

TooTallNate Mar 3, 2012

Dude, how did you figure this one out?? Nice!

Dude, how did you figure this one out?? Nice!

@rmaz

This comment has been minimized.

Show comment Hide comment
@rmaz

rmaz Mar 3, 2012

Contributor

with the power of grayskull, and to a lesser extent this doc page

Contributor

rmaz replied Mar 3, 2012

with the power of grayskull, and to a lesser extent this doc page

@creationix

This comment has been minimized.

Show comment Hide comment
@creationix

creationix Mar 3, 2012

Owner

i wonder if this works for ffi too... Those includes don't have any side effects other than declaring stuff right?

Owner

creationix replied Mar 3, 2012

i wonder if this works for ffi too... Those includes don't have any side effects other than declaring stuff right?

@rmaz

This comment has been minimized.

Show comment Hide comment
@rmaz

rmaz Mar 4, 2012

Contributor

the objc headers just declare functions that are used by the objc runtime, to send messages to objects and handle properties and so on. you can see the gory details here:

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html

Contributor

rmaz replied Mar 4, 2012

the objc headers just declare functions that are used by the objc runtime, to send messages to objects and handle properties and so on. you can see the gory details here:

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html

@TooTallNate

This comment has been minimized.

Show comment Hide comment
@TooTallNate

TooTallNate Mar 4, 2012

Oh, how intimately familiar I am with those crazy awesome functions :p

Oh, how intimately familiar I am with those crazy awesome functions :p

Please sign in to comment.