mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Avoid endless recursion when changing view from onFrame handler.
Closes #184.
This commit is contained in:
parent
e546848bcc
commit
96b886ae8d
1 changed files with 4 additions and 0 deletions
|
@ -183,6 +183,7 @@ var View = this.View = Base.extend(Callback, /** @lends View# */{
|
||||||
var now = Date.now() / 1000,
|
var now = Date.now() / 1000,
|
||||||
delta = this._before ? now - this._before : 0;
|
delta = this._before ? now - this._before : 0;
|
||||||
this._before = now;
|
this._before = now;
|
||||||
|
this._handlingFrame = true;
|
||||||
// Use Base.merge to convert into a Base object, for #toString()
|
// Use Base.merge to convert into a Base object, for #toString()
|
||||||
this.fire('frame', Base.merge({
|
this.fire('frame', Base.merge({
|
||||||
// Time elapsed since last redraw in seconds:
|
// Time elapsed since last redraw in seconds:
|
||||||
|
@ -194,6 +195,7 @@ var View = this.View = Base.extend(Callback, /** @lends View# */{
|
||||||
// Update framerate stats
|
// Update framerate stats
|
||||||
if (this._stats)
|
if (this._stats)
|
||||||
this._stats.update();
|
this._stats.update();
|
||||||
|
this._handlingFrame = false;
|
||||||
// Automatically draw view on each frame.
|
// Automatically draw view on each frame.
|
||||||
this.draw(true);
|
this.draw(true);
|
||||||
},
|
},
|
||||||
|
@ -234,6 +236,8 @@ var View = this.View = Base.extend(Callback, /** @lends View# */{
|
||||||
|
|
||||||
_redraw: function() {
|
_redraw: function() {
|
||||||
this._redrawNeeded = true;
|
this._redrawNeeded = true;
|
||||||
|
if (this._handlingFrame)
|
||||||
|
return;
|
||||||
if (this._animate) {
|
if (this._animate) {
|
||||||
// If we're animating, call _handleFrame staight away, but without
|
// If we're animating, call _handleFrame staight away, but without
|
||||||
// requesting another animation frame.
|
// requesting another animation frame.
|
||||||
|
|
Loading…
Reference in a new issue