swatteau/sokoban-rs

Panics calling unwrap on a None

Closed this issue · 2 comments

I run the game as suggested in the README, but as I press any key it crashes with this message:

thread 'main' panicked at 'called Option::unwrap() on a None value', /checkout/src/libcore/option.rs:335:20

Follows the backtrace

stack backtrace:
0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
1: std::sys_common::backtrace::_print
at /checkout/src/libstd/sys_common/backtrace.rs:69
2: std::panicking::default_hook::{{closure}}
at /checkout/src/libstd/sys_common/backtrace.rs:58
at /checkout/src/libstd/panicking.rs:381
3: std::panicking::default_hook
at /checkout/src/libstd/panicking.rs:397
4: std::panicking::rust_panic_with_hook
at /checkout/src/libstd/panicking.rs:577
5: std::panicking::begin_panic
at /checkout/src/libstd/panicking.rs:538
6: std::panicking::begin_panic_fmt
at /checkout/src/libstd/panicking.rs:522
7: rust_begin_unwind
at /checkout/src/libstd/panicking.rs:498
8: core::panicking::panic_fmt
at /checkout/src/libcore/panicking.rs:71
9: core::panicking::panic
at /checkout/src/libcore/panicking.rs:51
10: <core::option::Option>::unwrap
at /checkout/src/libcore/macros.rs:20
11: sdl2::event::Event::from_ll
at /home/gianmarco/.cargo/registry/src/github.com-1ecc6299db9ec823/sdl2-0.19.0/src/sdl2/event.rs:799
12: sdl2::event::wait_event
at /home/gianmarco/.cargo/registry/src/github.com-1ecc6299db9ec823/sdl2-0.19.0/src/sdl2/event.rs:1181
13: sdl2::event::::wait_event
at /home/gianmarco/.cargo/registry/src/github.com-1ecc6299db9ec823/sdl2-0.19.0/src/sdl2/event.rs:1251
14: sokoban_rs::main
at src/main.rs:110
15: __rust_maybe_catch_panic
at /checkout/src/libpanic_unwind/lib.rs:99
16: std::rt::lang_start
at /checkout/src/libstd/panicking.rs:459
at /checkout/src/libstd/panic.rs:361
at /checkout/src/libstd/rt.rs:59
17: main
18: __libc_start_main
19: _start

The unwrap() that triggers the panic seems to come from the following line in SDL2, which handles a key down event :

https://github.com/Rust-SDL2/rust-sdl2/blob/b3bc893863d31b8821f9058cb9b5d8377c3d6ed7/src/sdl2/event.rs#L799

My best guess is that the version of libsdl2 installed on your operating system does not quite match version 0.19.0 of the rust-sdl2 crate (which is a bit old now). You can check the exact versions of libsdl2 that I used at the time in the .travis.yml file (lines 14-16) :

https://github.com/swatteau/sokoban-rs/blob/a37a2d243bc28b688def7d3102d09e2d92f639b8/.travis.yml

Made a major upgrade of the game to rust-sdl2 v0.31 and it seems to work fine, so I'm closing this issue.