Skip to content

Commit

Permalink
More robust error prevention for saving block images.
Browse files Browse the repository at this point in the history
  • Loading branch information
acbart committed Sep 17, 2020
1 parent 0bf7aa9 commit dff68f6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/block_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ BlockMirrorBlockEditor.prototype.loadBlocklyCSS = function() {
* base64-encoded PNG and the IMG tag.
*/
BlockMirrorBlockEditor.prototype.getPngFromBlocks = function(callback) {
this.loadBlocklyCSS();
try {
this.loadBlocklyCSS();
// Retreive the entire canvas, strip some unnecessary tags
var blocks = this.workspace.svgBlockCanvas_.cloneNode(true);
blocks.removeAttribute("width");
Expand Down Expand Up @@ -350,6 +350,10 @@ BlockMirrorBlockEditor.prototype.getPngFromBlocks = function(callback) {
var canvas = document.createElement("canvas");
canvas.width = bbox.width;
canvas.height = bbox.height;
if (!canvas.width || !canvas.height) {
callback("", img);
return;
}
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0);
var canvasUrl;
Expand Down

0 comments on commit dff68f6

Please sign in to comment.