Closed k4kfh closed 8 years ago
Upon further testing, I found this has nothing to do with the train.all
object itself. Rather, i
in sim.accel
is getting screwed up somehow. Before the error occurs, i
becomes 29
for some reason, which obviously returns undefined
in an array with only a few elements.
I never did completely narrow down the source of the i = 29
problem, but I discovered a solution. In the initial declaration of i
(in the beginning of the for
loop), if I add the var
keyword to define it only in that scope, the problem disappears and everything works exactly as normal. So line 78 of sim.js
becomes this:
for(var i = 0; i < train.all.length; i++) {
I tested this pretty thoroughly, and the problem seems to be completely gone. All the DCC interfaces work totally as normal, all the previously functional dash gauges work (including RPM, which, since the problem occurred during ignition, is a good sign that nothing is broken as a result of my solution). I'm going to go ahead and close this issue after I commit that change.
sim.js
is saying that.prototype
is undefined. So somehow eitheri
is getting to be an improper number, or sim.js is beginning its cycles before thetrain.all
array is constructed. It's not a catastrophic bug from what I can tell, since it seems to fix itself after one cycle, so I'll deal with it when I can.