mfaerevaag
mfaerevaag

Reputation: 730

Meteor timers raise 'RangeError: Maximum call stack size exceeded'

I have a simple game based of the Meteor example 'wordplay'. Here, there's a timer in the background counting down time during gameplay. This timer is called when clicking a "Play" button. The problem occurs when the button is click.

Server-side:

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)

Client-side:

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

The error:

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

I have tried changing Meteor.setInterval to an recursive Meteor.setTimeout, but didn't change anything.

I have tried in multiple browsers and computers.

Upvotes: 0

Views: 1134

Answers (1)

David Weldon
David Weldon

Reputation: 64342

According to the docs:

Calling methods on the server defines functions that can be called remotely by clients. They should return an EJSON-able value or throw an exception.

Your CoffeeScript code is implicitly returning an interval handle which, I think, is putting the EJSON parser into a tailspin. If you just return anything else (end your method with any other expression) it will probably work fine.

Upvotes: 6

Related Questions