Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 line 716: i::Isolate* isolate = env->GetIsolate();.

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

share|improve this question
+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). – Jonathan Dickinson Jan 15 '12 at 19:59
@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 ;-) – Christian Ivicevic Jan 15 '12 at 21:36
up vote 6 down vote accepted


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.

share|improve this answer
(I can accept my own answer in 21 hours... I must wait again.) – Christian Ivicevic Jan 16 '12 at 19:02
Sometimes this SO rep thing is silly for decent users :). – Jonathan Dickinson Jan 16 '12 at 19:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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