amogh-dambal / diogenes-v2

V2 implementation of the Diogenes chess engine. This time in Rust.
0 stars 0 forks source link

`test_build_position_from_random_fen` crashes with a stack overflow #5

Closed amogh-dambal closed 6 months ago

amogh-dambal commented 6 months ago

The test simply takes a FEN string that represents an active, in-play position (i.e. not the starting position) and attempts to de-serialize the FEN into a Position struct and then re-serialize that struct back into a FEN string.

What's happening, instead, is that we get this error:

thread 'position::tests::test_build_position_from_random_fen' has overflowed its stack
fatal runtime error: stack overflow
error: test failed, to rerun pass `--lib`

This is odd behavior, and it likely has to do with something RE: how we're allocating stack frames in the impl Display for Square, since that's where the initial debugger crashed. But it needs more investigation.

To note, the test with the FEN string representing the starting position passes.

amogh-dambal commented 6 months ago

Issue resolved: The root cause was a circular call in impl Display for Square - the implementation called to_string(), which became self-referential until the call frames crashed the stack.