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的多臺計算機上看到此問題。任何建議,將不勝感激。