我具体说的是 unix.Window,它是包含 wayland 和 x11 实现的联合。
我完全没注意到错误出在调整大小事件的回调里,这个回调似乎会在 Window.init 期间立即调用,而我读取的正是应该存放当前正在初始化的窗口的那个变量,这就能解释我看到的问题了。这……也是个我不太喜欢的设计选择,不过我还没找到什么像样的替代库。
奇怪的是,出错的偏偏是联合访问,如果窗口变量本身就是 undefined,那读取它的 .backend 成员时不就应该先失败了吗?
从英语翻译·查看原文I'm referring specifically to unix.Window, a union containing wayland and x11 implementations.
What escaped me completely was that the error originates inside a resize event callback, which apparently runs straight away during Window.init, and I'm reading from the very variable which is intended to contain the window currently being initialized, so that would account for the problem I am seeing here. That's… another design choice I'm not especially keen on either, though I havent discovered any decent alternative libraries.
It seems rather curious that accessing the union specifically is where it fails, when the window variable itself contains undefined, wouldn't reading its .backend member already fail before that?