Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…he app will crash when SDL_SetVideoMode() is called
  • Loading branch information...
commit 709aa22b76cd7f16dcad73f6a65e4d940e1f0a5a 1 parent 3103ce2
Richard Mazorodze authored
Showing with 12 additions and 3 deletions.
  1. +12 −3 src/
15 src/
@@ -1,11 +1,21 @@
-#include "sdl.h"
-using namespace v8;
+#ifdef __APPLE__
+#include <objc/objc.h>
+#include <objc/objc-runtime.h>
+#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"));
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_BLUE_SIZE"), Number::New(SDL_GL_ACCUM_BLUE_SIZE));

5 comments on commit 709aa22


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


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


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


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:


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

Please sign in to comment.
Something went wrong with that request. Please try again.