amethyst / rustrogueliketutorial

Roguelike Tutorial in Rust - using RLTK
MIT License
905 stars 156 forks source link

Clothier has too many items, causes overflow issue #120

Closed Remimstr closed 4 years ago

Remimstr commented 4 years ago

Hey I want to start off by saying that I'm working my way through the tutorial and am enjoying it immensely, thank you so much for sharing this awesome project & guide with the world! I'm recording some suggestions and tweaks on my own fork as I go through it that I'll make a PR out of when I'm done :)

I was eagerly looking ahead so I checked out chapter-73-systems, ran the game, and then encountered this bug.

When I ask the clothier in the town to show me her stock, the app crashes with the following error:

thread 'main' panicked at 'attempt to subtract with overflow', chapter-73-systems/src/gui/vendor_menu.rs:129:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The offending line is let mut y = (25 - (count / 2)) as i32;, which led me to think that count (the # of inventory items) must be very large. A console::log led me to understand that the vendor has 67 items, way more than the 14 "clothes" category items in the raws! This is about as far as I can debug the issue for now, there's definitely something fishy going on. It's probably worth noting that I haven't experienced this with other vendors (though don't count on this as a thorough test).

On a related note, it may be a handy feature to have some sort of scroll functionality in the UI to avoid potential overflow errors like these.

thebracket commented 4 years ago

I think the issue is stemming from the auto-generation of magical clothing, and accidentally giving it to the vendor for sale. I'll see what I can do. Thanks!