i was able to compile and link V8 against my game and code interpretation works fine. However I want to divide my code and the game loop should exist in one thread and the scripting engine should run in a second thread alongside my game loop. I am using SDL and therefore tried this code to spawn a new thread

SDL_CreateThread(ScriptingEngine::SpawnMain, NULL);

where the following code is my test scripting engine:

namespace ScriptingEngine {
    v8::HandleScope handleScope;
    v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
    v8::Persistent<v8::Context> context;

    void Setup() {
            // TODO: bind functions to global
            // ...
            context = v8::Context::New(NULL, global);

    int SpawnMain(void *arguments) {
            v8::Context::Scope scope(context);
            v8::Handle<v8::Script> script = v8::Script::Compile(
                    v8::String::New("'Hello World'")
            v8::Handle<v8::Value> result = script->Run();
            return EXIT_SUCCESS;

However I get an error like Access violation reading location 0x00000000. in api.cc line 716: i::Isolate* isolate = env->GetIsolate();.

Has anyone a clue how I can fix this or what the exact problem is?

  • \$\begingroup\$ +1 for coming back with the answer. You should really answer your own question so you can mark it as answered (the S/O team encourage answering your own questions if you can). \$\endgroup\$ – Jonathan Dickinson Jan 15 '12 at 19:59
  • \$\begingroup\$ @JonathanDickinson: I have not enough reputation and therefore I am blocked for 8 hours until I a able to answer my own question. I will do this tomorrow ;-) \$\endgroup\$ – Christian Ivicevic Jan 15 '12 at 21:36


The solution was to use a monitor like v8::Locker locker;. Exactly this line must be entered the line before the creation of the HandleScope and it should work, although my code up there is crap. I have combined all variables etc. into one method without a setup method or the variables in ScriptingEngine.

Long story short: the Locker object is responsible for thread management as the engine isolates itself for sandboxing purposes.

  • \$\begingroup\$ Sometimes this SO rep thing is silly for decent users :). \$\endgroup\$ – Jonathan Dickinson Jan 16 '12 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.