I step through the code with the debugger. When I'm at the if-statement I expect that the next step will be either player = - player, or it will skip the whole block. BUT after the if-statement, it directly jumps to stack_set[sptr] = 0, which is not possible in any case.

In other programming languages, a similiar behavior is observed with highly optimized code sometimes, when assembly lines do no longer clearly correspond to a source code line. But in this case, nevertheless, sptr = sptr + 1 and player = - player after the block. But this is not the case.

In the code mentioned by you, there should not be such optimization (at least not written by me ;-). A dump of the generated bytecode would clarify the situation. I don't have a Thymio at hand, but will have a look tomorrow. BTW, it would be easier to reproduce if you can post the aesl script, it will include constants and so on.

However, rapidly looking at your code, in the event timer0, I saw the following lines:

sptr0 = move_cnt * 2
sptr = sptr

Is the assignment of sptr to sptr right? It looks suspicious. By searching through your code, sptr is never reset to a know value, it is only incremented or decremented.

To confirm, I disassembled the generated code. Looking at both the syntax tree, and the bytecode, I don't see problems related to the compiler. The problem probably comes from a memory corruption. Please, consider my first post.

Here are the syntax tree and the bytecode for the above-mentioned part of the code. For the bytecode, I interleaved the Aseba code, to make it easier to read.