在Windows上的LLDB内运行Rust OpenGL程序时窗口无法打开

时间:2018-12-25 17:02:59

标签: opengl rust lldb

我在Windows上有一个最小的Rust / OpenGL应用程序。我正在使用Visual Studio Code,LLDB和Glutin(类似于GLFW的库)。

通过cargo run启动会打开一个空窗口,但是通过LLDB启动时,不会打开任何窗口。我已经在LLDB和println!中确认了正在创建上下文创建函数并且正在执行主循环。换句话说,我已经验证了所有代码行。无论是否在VSCode中运行,都同样如此。

我使用的是32位Rust工具链,stable-i686-pc-windows-gnu,因为LLDB不完全支持64位Windows。除了这个问题,LLDB似乎按预期运行。

下面是main.rs,它是根据Glutin readme改编而成的。 (谷胱甘肽是类似于GLFW的Rust库。)我已删除了所有必需的东西,除了打开窗口所必需的东西。

所需的行为::从LLDB启动程序时,窗口打开,与从LLDB外部启动程序时一样。

实际行为::从LLDB启动程序时,该窗口不会打开。

问题:什么可以解释这种行为差异?即为什么从终端打开LLDB时窗口无法打开?


extern crate gl;
extern crate glutin;

fn main() {
    let events_loop = glutin::EventsLoop::new();
    let window = glutin::WindowBuilder::new();
    let context = glutin::ContextBuilder::new();

    // When running outside LLDB, this line causes the window to appear.
    // The let binding is necessary because without it, the value will be dropped
    // and the window will close before the loop starts.
    let gl_window = glutin::GlWindow::new(window, context, &events_loop).unwrap();

    // Normally, we'd make the window current here. But it's not necessary
    // to reproduce the problem.
    loop {
        // This is where we'd swap the buffers and clear. But it's not necessary
        // to reproduce the problem.
    }
}

1 个答案:

答案 0 :(得分:0)

部分答案:作为一种解决方法,您可以将LLDB 附加到正在运行的进程,而不是从LLDB 启动。在VSCode中,您可以使用Add Configuration -> LLDB: Attach by Name进行此操作。通过此工作流程,就像不涉及LLDB一样,将打开OpenGL窗口。不幸的是,依附在人体工程学上明显较少。

更新:我更喜欢使用调试器启动而不是附加。我发现Rust的MSVC x64工具链以及Microsoft的C / C ++调试器在此用例下效果很好。对我有用的步骤是:

  1. 如有必要,安装MSVC工具链:rustup install stable-x86_64-pc-windows-msvc
  2. 将MSVC工具链设置为默认值:rustup default stable-x86_64-pc-windows-msvc
  3. 更新Rust:rustup update
  4. 安装Microsoft's C/C++ extension for Visual Studio代码。该扩展程序包括与Rust编译的MSVC二进制文件兼容的调试器。
  5. 将调试配置添加到Visual Studio Code。我首先添加了默认配置,但必须对其进行修改。最终,这就是我在.vs-code/launch.json中所拥有的-请注意,字符串rust-test对于项目是唯一的:

-

{
  "name": "(Windows) Launch",
  "type": "cppvsdbg",
  "request": "launch",
  "program": "${workspaceFolder}/target/debug/rust-test.exe",
  "args": [],
  "symbolSearchPath": "${workspaceFolder}/target/debug/rust-test.pdb",
  "stopAtEntry": false,
  "cwd": "${workspaceFolder}/target/debug",
  "environment": [],
  "externalConsole": true
}

如果有人对LLDB问题有任何想法,我仍将不胜感激。尽管MSVC工具链目前已经解决了我的问题,但是可能还有其他一些人真的想使用LLDB并遇到这个问题。