Skip to content

Instantly share code, notes, and snippets.

@warpdesign
Created September 17, 2014 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save warpdesign/71eb501578ff76244e9d to your computer and use it in GitHub Desktop.
Save warpdesign/71eb501578ff76244e9d to your computer and use it in GitHub Desktop.
iOS 7.x Safari crash POC
var tilesSrc = 'img/gods.png',
tilesCanvas = null,
tilesImg = null;
function getCanvasFromImage(image) {
var canvas = document.createElement('canvas');
canvas.width = image.naturalWidth;
canvas.height = image.naturalHeight;
canvas.getContext('2d').drawImage(image, 0, 0);
return canvas;
}
window.onload = function() {
tilesImg = new Image();
tilesImg.src = tilesSrc;
tilesImg.onload = function() {
draw1.disabled = "";
draw2.disabled = "";
console.log("Image loaded");
// "convert" image to canvas (so that texture is in correct format)
tilesCanvas = getCanvasFromImage(this);
}
};
function drawTiles(ctx, from, w, h) {
ctx.clearRect(0, 0, 1024, 768);
var i = 0,
j = 0,
x = 56,
x2 = 0,
y = 0;
for (j = 0; j < 10; j++, y+= 32, x = 56, x2 = 0) {
for (i = 0; i < 14; i++, x += w, x2 += w) {
ctx.drawImage(from, x, 233, w, h, x2, y, w, h);
}
}
}
function draw(mode) {
var ctx = myCanvas.getContext('2d');
draw1.disabled = "disabled";
draw2.disabled = "disabled";
if (mode === 1) {
console.log('drawing using image as source');
drawTiles(ctx, tilesImg, 64, 32);
} else {
console.log('drawing using canvas as source');
drawTiles(ctx, tilesCanvas, 64, 32);
}
// disable buttons
draw1.disabled = "";
draw2.disabled = "";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment