【问题标题】:Meteor timers raise 'RangeError: Maximum call stack size exceeded'流星计时器引发“RangeError:超出最大调用堆栈大小”
【发布时间】:2013-12-15 18:30:54
【问题描述】:

我有一个基于 Meteor 示例“文字游戏”的简单游戏。在这里,后台有一个计时器,在游戏过程中倒计时。单击“播放”按钮时会调用此计时器。单击按钮时会出现问题。

服务器端:

start_new_game: (player_id) ->

# check player_id
return unless player_id

# TODO: Avoid getting the same questions
questions = Questions.find({}, {limit: 5}).fetch()

game_id = Games.insert
  current_points: START_POINTS
  current_question: 1
  question_ids: questions.map (q) -> q._id
  time_per_question: TIME_PER_QUESTION

Players.update({ _id: player_id },
  { $set: { game_id: game_id } }
)

points_per_question = START_POINTS / NUMBER_OF_QUESTIONS
points_per_second   = points_per_question / TIME_PER_QUESTION

clock = TIME_PER_QUESTION

# BOOM: Comment following line removes problem
unless interval then interval = setInterval((-> console.log 'COMON'), 1000)

客户端:

Template.lobby.events 
  'click button#startgame': ->
    Meteor.call 'start_new_game', current_player()._id

错误:

W2040-19:15:24.798(1)? (STDERR) /Users/markus/.meteor/tools/0b2f28e18b/lib/node_modules/fibers/future.js:173
W2040-19:15:24.800(1)? (STDERR)                         throw(ex);
W2040-19:15:24.802(1)? (STDERR)                               ^
W2040-19:15:24.803(1)? (STDERR) RangeError: Maximum call stack size exceeded
=> Exited with code: 8

我尝试将Meteor.setInterval 更改为递归Meteor.setTimeout,但没有更改任何内容。

我在多种浏览器和电脑上都试过了。

【问题讨论】:

    标签: meteor


    【解决方案1】:

    根据docs

    服务端调用方法定义了可以调用的函数 由客户远程。他们应该返回一个 EJSON-able 值或抛出 一个例外。

    您的 CoffeeScript 代码隐式返回了一个区间句柄,我认为这会将 EJSON 解析器置于一个尾旋中。如果您只是返回任何其他内容(以任何其他表达式结束您的方法),它可能会正常工作。

    【讨论】:

    • 哇,这是一个很好的收获!谢谢!不幸的是,错误被其他东西取代了。我会在几秒钟内更新问题。
    • 啊,它不见了。一切顺利。再次感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-06
    • 1970-01-01
    • 2021-05-30
    • 2021-07-11
    • 2019-07-05
    相关资源
    最近更新 更多