Hands-on Rust: B4.0 changing initialization code to use graphics (page 140)

On page 140 we change the initialization code of the dungeon crawler to be able to use graphics

image

As with other code examples before the relevant lines are annotated and explained afterwards. What I’ve noticed (and briefly struggled with) is that the first line also changed from:

let context = BTermBuilder::simple80x50()

to:

let context = BTermBuilder::new()

The change is small and easy to miss while the consequences are quite grave. If one misses the change and leaves the first line as BTermBuilder::simple80x50() the program will crash on startup with the following error:

thread 'main' panicked at 'Failed to load texture: IoError(Os { code: 2, kind: NotFound, message: "No such file or directory" })', /Users/swolf/.cargo/registry/src/github.com-1ecc6299db9ec823/bracket-terminal-0.8.1/src/hal/gl_common/font.rs:41:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I suggest to also highlight the change from BTermBuilder::simple80x50() to BTermBuilder::new() with an additional explanation on why this is necessary.

On another note: I’m very much enjoying the book. :slightly_smiling_face:

2 Likes