Permalink
Browse files

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

…he app will crash when SDL_SetVideoMode() is called
  • Loading branch information...
1 parent 3103ce2 commit 709aa22b76cd7f16dcad73f6a65e4d940e1f0a5a Richard Mazorodze committed Feb 27, 2012
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));
-
}
////////////////////////////////////////////////////////////////////////////////

0 comments on commit 709aa22

Please sign in to comment.