Make sure to guard against load errors.

This commit is contained in:
Rob Sayre 2011-07-04 14:25:33 -07:00
parent a4f8251d10
commit 1aa0b390b9

View File

@ -57,6 +57,7 @@ function nextTask() {
r.open("GET", task.file); r.open("GET", task.file);
r.mozResponseType = r.responseType = "arraybuffer"; r.mozResponseType = r.responseType = "arraybuffer";
r.onreadystatechange = function() { r.onreadystatechange = function() {
var failure;
if (r.readyState == 4) { if (r.readyState == 4) {
var data = r.mozResponseArrayBuffer || r.mozResponse || var data = r.mozResponseArrayBuffer || r.mozResponse ||
r.responseArrayBuffer || r.response; r.responseArrayBuffer || r.response;
@ -67,7 +68,7 @@ function nextTask() {
failure = 'load PDF doc: '+ e.toString(); failure = 'load PDF doc: '+ e.toString();
} }
task.pageNum = 1, nextPage(task); task.pageNum = 1, nextPage(task, failure);
} }
}; };
r.send(null); r.send(null);
@ -77,7 +78,7 @@ function isLastPage(task) {
return (task.pdfDoc && (task.pageNum > task.pdfDoc.numPages)); return (task.pdfDoc && (task.pageNum > task.pdfDoc.numPages));
} }
function nextPage(task) { function nextPage(task, loadError) {
if (isLastPage(task)) { if (isLastPage(task)) {
if (++task.round < task.rounds) { if (++task.round < task.rounds) {
log(" Round "+ (1 + task.round) +"\n"); log(" Round "+ (1 + task.round) +"\n");
@ -88,14 +89,17 @@ function nextPage(task) {
} }
} }
var failure = ''; var failure = loadError || '';
log(" loading page "+ task.pageNum +"... ");
var ctx = canvas.getContext("2d"); var ctx = null;
var fonts = []; var fonts;
var gfx = null; var gfx = null;
var page = null; var page = null;
if (!failure) {
log(" loading page "+ task.pageNum +"... ");
ctx = canvas.getContext("2d");
fonts = [];
try { try {
gfx = new CanvasGraphics(ctx); gfx = new CanvasGraphics(ctx);
page = task.pdfDoc.getPage(task.pageNum); page = task.pdfDoc.getPage(task.pageNum);
@ -103,6 +107,7 @@ function nextPage(task) {
} catch(e) { } catch(e) {
failure = 'compile: '+ e.toString(); failure = 'compile: '+ e.toString();
} }
}
if (!failure) { if (!failure) {
try { try {