当我的障碍列表太大时,为什么会出现此错误?

Why does this error occur when my list of obstacles gets too big?

我在javascript做一个无限跑酷游戏,屏幕上的障碍物数量对应分数(每1000分一个障碍物)。当分数超过 30 到 35,000(即 30 到 35 个障碍)时,我得到这个错误:

TypeError: Cannot read property 'render' of undefined
    at render (https://replbox.repl.it/data/web_hosting_1/GameMaster1928/Infinite-Runner-Thing/script.js:240:22)
    at loop (https://replbox.repl.it/data/web_hosting_1/GameMaster1928/Infinite-Runner-Thing/script.js:255:3)

我的代码在 https://repl.it/@GameMaster1928/Stuff。 我把这艘船弄得无敌了,所以你可以等着重现错误。

似乎我的障碍之一是由于某种原因变得不确定。有人可以看看我的代码并告诉我错误在哪里,以便我可以修复它吗?

obstacles[Math.floor(score / 1000)] = new Obstacle(); 如果您不为 1000 分调用它并跳过一个,这可能会出现问题。请改用 obstacles.push( new Obstacle())