tomassedovic / tcod-rs

Rust bindings for libtcod 1.6.3 (the Doryen library/roguelike toolkit)
Do What The F*ck You Want To Public License
229 stars 45 forks source link

Segfault running Dijkstra path finding example #310

Closed tomassedovic closed 3 years ago

tomassedovic commented 4 years ago
$ cargo run --example dijkstra-path-finding
   Compiling tcod-sys v6.0.0 (/home/shadower/code/tcod-rs/tcod_sys)
   Compiling tcod v0.15.0 (/home/shadower/code/tcod-rs)
    Finished dev [unoptimized + debuginfo] target(s) in 7.46s
     Running `target/debug/examples/dijkstra-path-finding`
Starting from: (4, 6)
Walking to: (4, 6)
Walking to: (3, 5)
Walking to: (2, 4)
Walking to: (1, 3)
Walking to: (0, 2)
Walking to: (1, 1)
Arrived at the destination!

Starting from: (0, 6)
Walking to: (0, 6)
Walking to: (1, 5)
Walking to: (0, 4)
Walking to: (1, 3)
Walking to: (0, 2)
Walking to: (1, 1)
Arrived at the destination!

fish: “cargo run --example dijkstra-pa…” terminated by signal SIGSEGV (Address boundary error)

This happens both with the current tcod-rs release (0.15.0) and with: https://github.com/tomassedovic/tcod-rs/pull/309

I suspect that means the error is probably in our bindings rather than libtcod itself, but maybe it is just a long-standing issue in the original codebase.

ojhp commented 3 years ago

Looks like an issue in libtcod itself where it can't reverse an empty list (the example that breaks is finding a path from the origin to itself). Can be protected against by checking for an empty list before calling the reverse function. A* is unaffected by this issue as far as I can see.