Search code examples
v8

V8 "Platform" is null


I'm calling "Isolate->IdleNotification(100)" within an isolate scope (via "v8::Isolate::Scope ..."), and at some point when "V8::GetCurrentPlatform()->CallOnBackgroundThread(...)" is called within V8, "V8::GetCurrentPlatform()" returns NULL, and the whole thing dies a fatal death. Any ideas why the current platform might be null? Or rather, what should be done to make sure it isn't? Everything else seems to be working just fine.

Addition details: I'm using Visual Studio 2013, and compiled the source, the resulting libraries of which I use with the V8.Net wrapper (on codeplex). I run the following code before triggering the idle notification call:

v8::Locker __lockScope(engine->Isolate());
v8::Isolate::Scope __isolateScope(engine->Isolate());
v8::HandleScope __handleScope(Isolate::GetCurrent());

I tried different combinations, and it seems only v8::Locker __lockScope is required, but the platform is still null;

v8::Platform* V8::GetCurrentPlatform() {   
    DCHECK(platform_);   // <-- 'platform_' is NULL
    return platform_; 
}

Solution

  • Got this working shortly after, but forgot to post the answer. Here it is: Google changed stuff (surprise! :/), and now you have to initialize a platform first. I did this and it all works again:

    v8::V8::InitializePlatform(v8::platform::CreateDefaultPlatform());
    // Sets the v8::Platform to use. This should be invoked before V8 is initialized.
    v8::V8::InitializeICU();
    // Initialize the ICU library bundled with V8. (if using the bundled ICU)
    v8::V8::Initialize();
    // Initialize V8.