Skip to main content
removed solution to answer own question
Source Link

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();
            context.Dispose();
            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?

Solution

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.

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();
            context.Dispose();
            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?

Solution

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.

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();
            context.Dispose();
            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?

Tweeted twitter.com/#!/StackGameDev/status/158601155398746113
found solution
Source Link

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();
            context.Dispose();
            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?

Solution

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.

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();
            context.Dispose();
            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?

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();
            context.Dispose();
            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?

Solution

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.

Source Link

Why does V8 not run with SDL threads?

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();
            context.Dispose();
            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?