我最近开始涉足 DerelictGLFW。我有两个类,一个是一个Window
类,另一个是一个InputHandler
类(窗口事件的事件管理器)。在我的光标位置回调中,我获取窗口用户指针并尝试设置位置,但在尝试设置回调和 GLFW 之外的任何值时,我立即收到访问冲突错误。GLFW 已初始化,不报告任何错误。感谢您的时间。
Class Window
{
private:
double cursorX;
...other stuffs...
@property
void cursorX(double x) nothrow
{
cursorX = x;
}
}
extern(C) void mousePosCallback(GLFWwindow* window, double x, double y)
{
Window* _window = window.userPointer
//userPointer is a static function that gets the window user pointer
//and casts it to a Window*
_window.cursorX = x;
}
static Window* userPointer(GLFWwindow* window)
{
return cast(Window*) glfwGetWindowUserPointer(window);
}
编辑:
添加extern(C)
到回调,错误仍然存在。
将“立即进入回调”更正为“立即尝试设置回调和 GLFW 之外的任何值”。
增加userPointer
提问功能