Skip to content

HTTPS clone URL

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/sdl.cc
View
15 src/sdl.cc
@@ -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

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

@rmaz

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

@creationix
Owner

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

@rmaz

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

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.