我写了一个Node.js插件,用于Electron框架 插件的主要条目调用另一个C ++库,该库进行长时间运行,因此我将回调放入以获得操作进度的报告。 所以C ++库在我的插件中调用了一个回调,但是Isolate是null,所以我尝试创建一个新的 隔离是很好的创建,但当我尝试使用它有新的本地我有这个错误:
electron.exe中0x0000000000000000处抛出异常:0xC0000005:访问冲突执行位置0x0000000000000000。
以下是我的代码的摘录(progress_cb
变量在插入Javascript调用中传递的函数的插件的主条目中取值:
Local<Function> progress_cb;
class ArrayBufferAllocator : public ArrayBuffer::Allocator {
public:
virtual void* Allocate(size_t length) {
void* data = AllocateUninitialized(length);
return data == NULL ? data : memset(data, 0, length);
}
virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
virtual void Free(void* data, size_t) { free(data); }
};
void progress_callback(int read, int write, int total)
{
V8::Initialize();
ArrayBufferAllocator allocator;
Isolate::CreateParams params;
params.array_buffer_allocator = &allocator;
Isolate* isolate = Isolate::GetCurrent();
if (!isolate) {
isolate = Isolate::New(params);
isolate->Enter();
}
const unsigned argc = 3;
Local<Integer> r = Int32::New(isolate, (int32_t)read);
Local<Integer> w = Int32::New(isolate, (int32_t)write);
Local<Value> t = Int32::New(isolate, (int32_t)total);
Local<Value> argv[argc] = { r, w, t };
progress_cb->Call(isolate->GetCurrentContext()->Global(), argc, argv);
}
有什么建议吗?