You know all the sayings about assumptions. They all boil down to don't take things for granted but how do you know when you are making an assumption?
I have been chasing a problem with my grenade throwing code. They would
disappear unexpectedly or explode at the wrong time or place.
I have lots of visualisation to confirm that the calculations are being performed and that the positions were correct and in view!
It turns out that the confusion was because I had unconsciously assumed that my update
thread was always in advance of my draw thread.
Nearly everywhere else in the code the update does not matter if it runs out of sync with the draw thread but for grenades that have to bounce, the difference was noticeable. The collision is calculated in one thread but the grenade is drawn in another thread in real time.
Overall the update thread does less work and so has plenty of spare performance therefore it seamed logical in the back of my mind that it would process the collision faster than needed. What I had not allowed for is that it might have started after the draw thread.
I had varying results that I could not explain. Sometimes working and sometimes not which I now know is because it is multi-threaded. The launching of the grenade could sometimes be picked up instantly by the draw thread because that is where it was in its cycle but the update thread could be a few milliseconds or even a frame behind that draw.
Problem solved and another lesson learnt :-)