The game crashed when I tried to add a rail where there already were 4 segments, also it was being by several trains. There is another junction like this (this one was being used too), I tried adding the new line there and it crashed again.
Then I tried adding the rail with the trains set to manual and it suddenly worked! So i guess it has something to do with modifying segments which are in a train's path.