I can not over emphasise the importance of maintaining good standards of trackwork. I've been a Track man for 49 years 11 months, and 6 days, now. Part of my job is doing Derailment Analysis.
Sure, there are important things like track gauge, and the interaction with wheel gauge on your rolling stock, but by far, the biggest cause of derailments, both model and prototype, is twist in the track.
Let's consider, in no particular order, the parameters of track measurement.
Line. This is what it says, a straight should be straight etc. On curves the line should bend evenly. Peeky joints are the biggest line fault.
Top. This is the evenness of the tops of the rails. Dips at the joints can cause problems. With models, poor top can cause uncoupling etc.
Gauge. There is tolerance here, too wide, or tight and coupled with wheels not being right, you get squeeze offs, or drop ins.
Cant. Or superelevation, for our American friends, is a scientific value to stop trains tipping over sideways on curves. It is speed related. Avoid it with models, because you have to deal with
Run Off, which is the rate of change of cant in the transition/spiral. In reality, you need a pretty long spiral to do it right. Do it too short, then all 4 wheels will not be on the rails at the same time, which will have the same effect as
Twist. This is where there is a big change of cant in a very short distance, particularly fatal on curves.
So, now, before you go disassembling your loco and rolling stock (and I've seen this done numerous times), check your trackwork. By now, the world is conscious of bubbles, and the bubble is the trackman's friend. If you haven't got one of those Aristo Track Gauges (best investment I ever made in the model sphere), get a cheap spirit level (some builder's squares often have one in them) for checking and levelling up your track.