Rust游戏引擎Bevy初探

那天我偶然看到一个使用Rust编写的游戏引擎(其实是我刻意找的,就是这么自虐),瞬间有了操起来玩玩的兴致,可还没让小妮给爷笑一个就先被它折腾的换了内核。怎么回事,且听我慢慢说。

下载Bevy项目尝试运行实例游戏,报错了:


tianlang@tianlang:rust$ git clone https://github.com/bevyengine/bevy
正克隆到 'bevy'...
remote: Enumerating objects: 292, done.
remote: Counting objects: 100% (292/292), done.
remote: Compressing objects: 100% (231/231), done.
remote: Total 29614 (delta 126), reused 161 (delta 60), pack-reused 29322
接收对象中: 100% (29614/29614), 32.77 MiB | 157.00 KiB/s, 完成.
处理 delta 中: 100% (18934/18934), 完成.


tianlang@tianlang:rust$ cd bevy/


tianlang@tianlang:bevy$ cargo run --example breakout
...
Compiling ab_glyph v0.2.10
error: failed to run custom build command for `libudev-sys v0.1.4`

Caused by:
  process didn't exit successfully: `/data/code/github/rust/bevy/target/debug/build/libudev-sys-ee6a5de081f0ae93/build-script-build` (exit code: 101)
  --- stdout
  cargo:rerun-if-env-changed=LIBUDEV_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=LIBUDEV_STATIC
  cargo:rerun-if-env-changed=LIBUDEV_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR

  --- stderr
  thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "`\"pkg-config\" \"--libs\" \"--cflags\" \"libudev\"` did not exit successfully: exit code: 1\n--- stderr\nPackage libudev was not found in the pkg-config search path.\nPerhaps you should add the directory containing `libudev.pc\'\nto the PKG_CONFIG_PATH environment variable\nNo package \'libudev\' found\n"', /home/tianlang/.cargo/registry/src/github.com-1ecc6299db9ec823/libudev-sys-0.1.4/build.rs:38:41
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed

查看bevy官方文档是没有安装系统依赖,我使用的ubuntu18,执行安装命令:

sudo apt-get install pkg-config libx11-dev libasound2-dev libudev-dev

sudo apt-get install clang

安装完成后,可以正常编译示例,但运行失败:

tianlang@tianlang:bevy$ cargo run --example breakout
    Finished dev [unoptimized + debuginfo] target(s) in 0.13s
     Running `target/debug/examples/breakout`
thread 'main' panicked at 'Unable to query surface formats: ERROR_UNKNOWN', /home/tianlang/.cargo/registry/src/github.com-1ecc6299db9ec823/gfx-backend-vulkan-0.7.0/src/window.rs:315:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Mar 30 22:08:25.706 ERROR gpu_descriptor::allocator: `DescriptorAllocator` is dropped while some descriptor sets were not deallocated
Mar 30 22:08:25.706 ERROR gpu_alloc::block: Memory block wasn't deallocated
Mar 30 22:08:25.706 ERROR gpu_alloc::block: Memory block wasn't deallocated
段错误

从错误信息看是Vulcan出了问题,执行vulkaninfo确认下,果然这小子有异常:

$vulkaninfo
/build/vulkan-tools-136mCR/vulkan-tools-1.1.126.0+dfsg1/vulkaninfo/vulkaninfo.h:803: failed with UNKNOWN_VkResult
段错误

$dmsg

[ 2016.528891] nvidia-modeset: Version mismatch: nvidia.ko(460.67) nvidia-modeset.ko(460.56)
[ 2016.933217] PKCS#7 signature not signed with a trusted key
[ 2016.935729] nvidia-modeset: Version mismatch: nvidia.ko(460.67) nvidia-modeset.ko(460.56)
[ 2017.344852] PKCS#7 signature not signed with a trusted key
[ 2017.346405] nvidia-modeset: Version mismatch: nvidia.ko(460.67) nvidia-modeset.ko(460.56)
[ 2017.460432] vulkaninfo[6255]: segfault at 6b6e696c678d ip 00007f703abf8fd0 sp 00007ffc7ba2c218 error 4 in libpthread-2.27.so[7f703abef000+1a000]
[ 2223.351496] traps: vulkaninfo[7640] general protection ip:7f568663ffd0 sp:7ffc4afb7b68 error:0 in libpthread-2.27.so[7f5686636000+1a000]

从dmsg错误信息猜测应该是跟库不匹配有关,重新下载vulcan sdk  参照博客安装.还是一样的错误,涛声依旧.

看来得放大招了,升级内核吧.由于我用的elementary os是基于ubuntu18开发的可以参考这里升级内核,原来的内核是:

$ uname -r
4.15.0-36-generic

升级后:

tianlang@tianlang$ uname -r
5.4.0-71-generic

重启后再次执行vulkaninfo显示信息与从前大不一样,执行vkcube竟然能看到传说中的正方体了:

不容易啊!趁胜追击再运行下bevy示例,也终于正常了.

哎呦,这运行界面是不是跟我们的Rust课程里的乒乓球游戏有些许相似,收工!!!


猜你喜欢

转载自blog.51cto.com/14256460/2678976