当我尝试制作 wgpu 表面时,出现此错误:
error[E0277]: the trait bound `Window: raw_window_handle::HasRawDisplayHandle` is not satisfied
--> src/lib.rs:34:56
|
34 | let surface = unsafe { instance.create_surface(&window) }.unwrap();
| -------------- ^^^^^^^ the trait `raw_window_handle::HasRawDisplayHandle` is not implemented for `Window`
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait `raw_window_handle::HasRawDisplayHandle`:
&'a T
raw_window_handle::borrowed::DisplayHandle<'_>
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
let surface = unsafe { instance.create_surface(&window) }.unwrap();
我不知道如何解决这个问题,我尝试修复但一切都是徒劳的。
我有一个简单的 winit 应用程序,它创建一个空窗口并运行 EventLoop:
event_loop.run(move |event, _, control_flow| {
control_flow.set_wait_until(std::time::Instant::now() + Duration::from_millis(1000));
match event {
Event::WindowEvent{ ref event, window_id, } => {},
Event::MainEventsCleared => {
window.request_redraw()
},
_ => {}
}
});
Run Code Online (Sandbox Code Playgroud)
在 MacOS 上,此进程 100% 使用 1 个 CPU 核心。如果我删除 window.request_redraw 调用,或者当我人为地限制线程睡眠时(无论设置等待直到控制流程),CPU 使用率会急剧下降到 10% 左右。这表明 wait/wait Until 无法正常工作,因为如果我理解正确的话,我希望每 1 秒才会看到对 request_redraw 的调用。
除了 thread::sleep/wait/wait Until 之外,还有什么方法可以限制事件循环运行频率,或者我做错了什么?