Why does V8 not run with SDL threads?

Christian Ivicevic
  • Why does V8 not run with SDL threads? Christian Ivicevic

    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.

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

Tags
c++ javascript sdl multithreading
Related questions and answers
  • ;* bullets = new std::vector<Missile*&gt;(); void FireBullet(Ship* s) { if (bullets-&gt;size() < Constants::MAXBULLETS) { Missile* missile = new Missile...)-&gt;Alive == true) { bullets-&gt;at(index)-&gt;Draw(buffer, sprite); } } } //Entry point of the application int main(void) { Ship* s = new Ship(); int x...To begin with I am developing a PSP application so I have no clue how to debug a PSP application. That doesn't mean I do not know how debug period. Anyway, when I run the game everything runs fine

  • I'm writing a simple class to draw all the debugging lines I have in my scene at once. The code in the draw loop is this so far: (If I put for example, 2 instead of temporary2DVerts.size() where I have marked with //THIS LINE, the code works fine.) when I run the code below the line breaks //HERE. Access violation reading location 0x00000000. seems like the create buffer line is not working...; bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; bd.MiscFlags = 0; device-&gt;CreateBuffer(&bd, NULL, &pBuffer); void* pVoid; pBuffer-&gt;Map(D3D10_MAP_WRITE_DISCARD, 0, &pVoid); //HERE memcpy(pVoid

  • I am making a game using OpenGL, with SDL_Image employed to load the textures. When drawn on screen, there's no alpha -- in an exact square around the opaque contents of the texture, black is drawn; outside that space, white is drawn. Here is my OpenGL init code... SDL_SetVideoMode(windowWidth, windowHeight, 16, SDL_HWSURFACE|SDL_GL_DOUBLEBUFFER|SDL_OPENGL); glClearColor(0, 0, 0, 0... = SDL_DisplayFormat(zoomedImage); SDL_FreeSurface(zoomedImage); } return optimizedImage; } ...here is the code I actually use to create the GL texture... GLuint thisIsMyTexture

  • , texscale + sourceY); glVertex2i(x, y + tileHeight); glEnd(); glLoadIdentity(); My initialization code for OpenGL: // Set the OpenGL state after creating the context with SDL_SetVideoMode glClearColor(0... tile being rendered, but I'm getting a blurred mess :S. My rendering code: glBindTexture(GL_TEXTURE_2D, texture); float texscale = 1.0f / (float)tileWidth; sourceX = sourceX / (float)tileSheetWidth...(); glOrtho(0, Width, Height, 0, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); Just in-case, here's my image loading code, I think that perhaps this may be were the problem lies somehow

  • code in them... Right now for testing purposes, I just have the main loop call Level1 level1; and use the functions, but when I run the game I get a segmentation fault. This is the first time I've... that'll have the inherited level classes pushed onto it...This is what my code looks like at the moment, I've tried various things and get the same result (segmentation fault). //level.h class Level... supposed to include in the inherited class structure, but this is what I have at the moment... //level1.h class Level1: public Level { public: Level1(); ~Level1(); void load(); void

  • ))) { MessageBox(NULL, L"You're a terrible programmer!", L"ERROR", MB_OK); stopEverything = true; } else { pd3dDevice -&gt; CreateOffscreenPlainSurface(Info.Width, Info.Height...(); } // present the back buffer contents to the display pd3dDevice -&gt; Present(NULL, NULL, NULL, NULL); } void cleanUp (void) { // release the device and the Direct3D object if (pd3dDevice...i think i just found the solution. 1) the problem is that backbuffer surface and source surface are of different formats - that is why exception was thrown. 2) the image path needed double slash "C

  • }; // for the old/new screen command // Some nCurses setup int r = 0, c = 0; // current row and column (upper-left is (0,0)) const int nrows = 56, // number of rows in window ncols = 79...: /////////////////////////////////////////// Screen Variables /////////////// string _name; vector <string> new_map; vector <string> old_map; vector <Sprite*&gt; sprites_p; public: Screen... /////////////////////////// void Refresh(int command= ALL, int transition= NONE) { //old_map = new_map; // update the old map for(int r= 0; r< nrows; r++){ move(r,0); addstr

  • I am trying to build and run Doom 3 from the open source release in order to better understand how the engine works. Unfortunately I am not able to run the game from the binary I built. I just get the console, but cannot run the actual game. Here is what I did: Downloaded the source code from the game repo Downloaded and installed the DirectX SDK Purchased, downloaded and installed Doom 3 from... installation path. This is the default command line arguments used to run the project from vstudio. +set fs_basepath "C:\Program Files (x86)\Steam\steamapps\common\doom 3" +set com_allowConsole 1 +set si

  • I am quite new to OpenGL, I have managed after long trial and error to integrate Nehe's Cel-Shading rendering with my Model loaders, and have them drawn using the Toon shade and outline... ) if (In) // Check To See If The File Opened ( NEW ) { for (i = 0; i < 32; i++) // Loop Though The 32 Greyscale Values ( NEW...); // Set The Color Of The Model ( NEW ) // ORIGINAL DRAWING CODE //Draw the model as an interpolation between the two frames glBegin(GL_TRIANGLES); for(int i = 0; i

Data information