2016-04-14 84 views
0

我正在为Node.js创建一组GLFW 3.1.2绑定。我遇到了一个特定API的问题,特别是glfwSetMonitorCallback API。GLFW监视器回调未触发

问题是,当我断开连接或将监视器连接到我的系统时,它没有被触发。

以下是我的回调处理程序:

void monitor::onGLFWMonitor (GLFWmonitor* monitor, int action) { 
    Isolate* isolate = Isolate::GetCurrent(); 
    HandleScope scope(isolate); 

    auto it = monitor::monitorObjects.find(monitor); 
    Local<Object> jsMonitor; 

    if (it == monitor::monitorObjects.end()) { 
     // New monitor, add it 
     jsMonitor = monitor::monitorObjectTemplate.Get(isolate)->NewInstance(); 
     jsMonitor->SetAlignedPointerInInternalField(0, monitor); 
     jsMonitor->SetInternalField(1, String::NewFromUtf8(isolate, "GLFWmonitor")); 
     CopyablePersistent<Object> perst(isolate, jsMonitor); 
     MonitorIndexedPair<Object> pr(monitor, perst); 
     it = monitor::monitorObjects.insert(pr).first; 
    } else { 
     jsMonitor = it->second.Get(isolate); 
    } 

    if (action == GLFW_DISCONNECTED) { 
     // Monitor removed, clean up! 
     jsMonitor->SetAlignedPointerInInternalField(0, NULL); 
     monitor::monitorObjects.erase(it); 
     // TODO Cleanup video modes once implemented 
    } 

    if (monitor::monitorCallback.IsEmpty()) { 
     // No callback, do nothing 
     return; 
    } 

    Local<Function> callback = monitor::monitorCallback.Get(isolate); 
    const unsigned int argc = 2; 
    Local<Value> argv[argc] = { 
     jsMonitor, 
     Number::New(isolate, action) 
    }; 
    callback->Call(isolate->GetCurrentContext()->Global(), argc, argv); 
} 

它被设置为任何呼叫的部分glfwInit像这样:

void core::init (const FunctionCallbackInfo<Value>& args) { 
    Isolate* isolate = Isolate::GetCurrent(); 
    HandleScope scope(isolate); 

    bool result = glfwInit(); 

    if (result == GL_TRUE) { 
     // Setup callbacks 
     glfwSetMonitorCallback(monitor::onGLFWMonitor); 
    } 

    args.GetReturnValue().Set(Boolean::New(isolate, result == GL_TRUE)); 
} 

我增加了一些printf语句转换为回调函数,并没有他们是有史以来生产的。此外,如果我拨打glfwGetMonitors,它总是返回错误的显示器数量。 EG:我有两台显示器,断开连接,glfwGetMonitors仍然返回两台显示器。

我在运行Windows 7,Windows 8/8.1和Windows 10的多台计算机上看到此问题。任何建议,将不胜感激。

回答

0

经过多一点挖掘,我确定了我的问题的原因。我写的简单测试用例从来不叫glfwPollEvents,所以我的回调自然不会被触发。