【问题标题】:Window doesn't open when running a Rust OpenGL program inside of LLDB on Windows在 Windows 上的 LLDB 中运行 Rust OpenGL 程序时,窗口不会打开
【发布时间】:2019-05-24 06:01:35
【问题描述】:

我在 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。 (Glutin 是一个类似于 GLFW 的 Rust 库。)除了打开窗口所需的必需品外,我已经删除了所有内容。

期望行为:当程序从 LLDB 启动时,窗口打开,与程序从 LLDB 外部启动时打开的窗口相同。

实际行为:当程序从 LLDB 启动时,窗口没有打开。

问题:什么可以解释这种行为差异? IE。为什么从终端打开时,窗口不会从 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.
    }
}

【问题讨论】:

  • 您没有寻找任何错误返回原因?那个基本的。
  • 是的,你是对的——非常基本。如果有任何此类信息,我肯定会在我的问题中说明。

标签: opengl rust lldb


【解决方案1】:

部分答案:作为一种解决方法,您可以附加 LLDB 到正在运行的进程,而不是启动 LLDB 中的进程。在 VSCode 中,您可以使用:Add Configuration -> LLDB: Attach by Name 执行此操作。使用此工作流程,OpenGL 窗口会像不涉及 LLDB 时一样打开。不幸的是,这种连接方式明显不太符合人体工程学。

更新:我更喜欢使用调试器启动而不是附加。我发现 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. 为 Visual Studio Code 安装 Microsoft's C/C++ extension。该扩展包含一个与 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 并遇到这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-05
    • 2022-08-17
    • 2013-09-29
    • 1970-01-01
    • 2017-06-30
    • 1970-01-01
    • 2019-02-17
    • 2012-06-09
    相关资源
    最近更新 更多