Permalink
Browse files

try/catch to avoid Uncaught Error: INDEX_SIZE_ERR: DOM Exception 1

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information...
1 parent 5bd69f4 commit 1ab552f8aa9289ec0c692bf28fade97f915e6ac8 @rwaldron rwaldron committed Jun 6, 2012
Showing with 16 additions and 10 deletions.
  1. +16 −10 performance/src/sprite.js
View
@@ -11,16 +11,22 @@ function Renderer( src ) {
Renderer.prototype = {
render: function( frame, bounds, context ) {
- context.drawImage(
- // Draw the entity...
- this.image,
- // On the cell...
- frame.left, frame.top,
- frame.width, frame.height,
- // Within the current calculated bounds...
- bounds.left, bounds.top,
- frame.width, frame.height
- );
+
+ // Wrap the drawImage call in try/catch to avoid
+ // Uncaught Error: INDEX_SIZE_ERR: DOM Exception 1
+ // when the canvas and image have gone away
+ try {
+ context.drawImage(
+ // Draw the entity...
+ this.image,
+ // On the cell...
+ frame.left, frame.top,
+ frame.width, frame.height,
+ // Within the current calculated bounds...
+ bounds.left, bounds.top,
+ frame.width, frame.height
+ );
+ } catch ( e ) {}
return this;
}

0 comments on commit 1ab552f

Please sign in to comment.