Thank you for this. I think that I have been able to fix this without using the debugger - I should be grateful if anyone could test with to-morrow's nightly build.
This code change was implemented to make this function deterministic: the equivalent function for signalboxes had caused the serious loss of synchronisation problem that took 6 months to solve recently and which was solved by implementing an equivalent change. I had not remembered that each specific waytype had its own depot type (I seem to remember copying this from some code that also specified only these types of depots, although I cannot now recall where), and must have assumed that these depot types were sufficient to cover others (which I must have assumed were implemented as subtypes).
I am not sure why the code for building vehicles from a depot has to search for the depot on a particular piece of ground in order to complete the building, but I have now modified the function to specify each depot type separately, so hopefully this should work (testing with trams seems to confirm this).