Hands on Rust: Need help with error - thread 'main' panicked at 'Failed to load texture

Hi, I need some help, I’m new to rust and was learning through your book. but I got stuck at the last stage of distribution. Whenever I try to run the release binary by double-clicking it gives me the following error. I even ran the source code from Github itself and have also copied the resources folder.

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

Sorry about formatting; replying one handed from my phone with a baby in the other! You need to include your resources directory in the same folder as the executable. So:
My_game_exec
resources/
resources/fontfiles (the png files)

Hope that helps!

1 Like

No problem at all. Thank you for taking the time and replying Sir.

I have done exactly as the book said and have kept the resources directory in the same folder with the executable including all the resource files too.

I used the “cargo build --release” command to create the binary and then copied the executable from the target/release. I’ve also tried to use the debug build. It gives me the same result. I used the code from Github too but I get the same results.

Side Note: When I embed all the resources like embedded_resource!(TERMINAL_FONT, "../resources/terminal8x8.png");, the program works.

1 Like

I’m going through this now, and have the same problem as kolossal. This is on a Mac. Could either of you provide an explanation of how/where to put these “embedded_resource” calls to make the program work?

It looks like kolossal is right - you need to use the path relative to the source-code file to embed the resources. So embedded_resource!(TERMINAL_FONT, "../resources/terminal8x8.png"); is correct.

You can also ship the game with the resources/ folder - but embedding is more elegant.

What I mean is, if I ship the game with its resources folder (as in kolossal’s screenshot, or on p.289 of your book), the game will not run. Could that be because resources are referenced as in “resources/” instead of “…/resources/” in main.rs and template.rs?

If the only solution is to use the “embedded resource” line, where does it go in the code?