You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用bracket-lib基础示例崩溃:触发slice::from_raw_parts不安全前置条件违规

关于bracket-lib运行"Hello, world"示例时的panic问题

我正在通过Herbert Wolverson所著《Hands-on Rust: Effective Learning through 2D Game Development and Play》学习Rust,目前处于第一部分第3节,任务是使用bracket-lib构建简单游戏。

按照书中内容运行基础"Hello, world"示例时,执行cargo run触发如下panic:

thread 'main' panicked at core/src/panicking.rs:221:5:
unsafe precondition(s) violated: slice::from_raw_parts requires the pointer to be aligned and non-null, and the total size of the slice not to exceed 'isize::MAX'
note: run with 'RUST_BACKTRACE=1' environment variable to display a backtrace
thread caused non-unwinding panic. aborting.
Aborted (core dumped)

已做的排查:

  • 逐行检查代码未发现问题
  • VSCode搭配rust-analyzer未提示任何错误
  • 代码已上传至GitHub仓库

使用环境:

  • 操作系统:Fedora 41(已完全更新)
  • Rustup版本:rustup 1.27.1 (54dd3d00f 2024-04-24)
  • rustc版本:rustc 1.83.0 (90b35a623 2024-11-26)

希望有人能指点方向,感谢帮助。

内容的提问来源于stack exchange,提问作者Void4

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 03:13:11