1

For some reason Safari on iPad is throwing an error when I draw an image as follows:

INDEX_SIZE_ERR:DOM Exception 1: Index or size was negative, or greater than the allowed value

var img = new Image;
img.src = node.data.userimg;
ctx.drawImage(img, 20, 20, 38, 38);

where node.data.userimg is a URL to a twitter profile icon. This error is not thrown in normal desktop browsers. Originally these imgs were drawn at a dynamic point in relation to the node object but even setting them statically at 20, 20 is still throwing this error. Can iPad's Safari not scale images without throwing this error? The images all seem to still draw in correctly if a bit slowly on most draw calls. I fear it might just be a performance issue since so much is being drawn on the canvas (a graph representing cities and associated tweets when clicked/touched).

Primus202
  • 648
  • 7
  • 24
  • console.log(node.data.userimg); What is the value exactly? – Simon Sarris Sep 28 '11 at 20:21
  • I'll try it but I'm doing checks to make sure its not null or empty. Otherwise it's pulled from twitter JSON results for the user_image. – Primus202 Sep 29 '11 at 15:48
  • It's possible that the image is not finished loading on the iPad. Can you wrap drawImage inside of an onload event? – Simon Sarris Sep 29 '11 at 15:53
  • That sounds like a likely answer since the performance is pretty slow cause of all the data being drawn. I'll probably want to also make sure the onload is stopped on the next draw call though since otherwise I'll have a queue of draw commands building up. Also, declaring the images outside of the draw command will probably help. – Primus202 Sep 29 '11 at 15:58

1 Answers1

1

Maybe these links help you ...

there is a chance that you get negative values... or that the image has not loaded before you want to draw it...

Both cases are not much liked by the canvas...

http://blog.ryanrampersad.com/2010/06/04/index_size_err-dom-exception-1-html-canvas/ Canvas: JavaScript Uncaught Error: INDEX_SIZE_ERR: DOM Exception 1

Uncaught Error: INDEX_SIZE_ERR

HTH

Community
  • 1
  • 1
silverfighter
  • 6,762
  • 10
  • 46
  • 73