Sometimes when a train rides over a rail switch, it goes the wrong way. I
have to ride far back and then try it again. Sometimes even that doesn't
work, I have to switch the track twice and then the train takes the correct
way.
More specifically: When a train passes the switch in the opposite
direction (from one of the diverging tracks to the common one) and the
switch was set to the other way, the switch will flip to the rail from
which the train went but the graphics does not refer that. When the
train (or another one) then tries to move through the switch, it will
"go the wrong way".
Maybe you shall look at the switch node (and its rotational metadata)
when deciding which way the train shall go instead of using some other
metadata that may become unsynchronized with the switch node.
What is strange, this doesn't happen in all cases you described above. Only
something like 30% of switch nodes behave this way. And some of them are
buggy only sometimes.
Also, the graphic should always refer to the current state of switch, so
it's definitely a bug.
Hello
This is indeed a known issue. The exact cause is as follows:
Every train generates a list of track positions , the so-called "path",
when it rides along the track. The so-called "index" tells where on the
path the train is located at the moment. When a train moves, the index
is increased or decreased, and then the path is extended as needed to
cover the space the train occupies. Every wagon then independently
constructs its position and orientation from the train's path and index
and its own position in the train. Path elements that are too far away
from the train are deleted.
When a train has passed over a wrongly oriented switch, the path still
holds the "wrong" route. Unless you continue driving forward for another
10-20 nodes, which is when those wrong path items got deleted, the train
will continue on the old, "wrong" path backwards.
However, the path is invalidated and fully regenerated whenever a switch
is switched. This is why it works when you flip the switch twice.
In the current development version (the TSS branch) the issue is fixed.
Trains then regenerate their whole path when they reverse. (see also
this forum post
https://forum.minetest.net/viewtopic.php?f=11&t=14726&p=337551#p337551)