Skip to content

Commit

Permalink
Fix crash when resurfacing SVG canvases
Browse files Browse the repository at this point in the history
  • Loading branch information
zbjornson committed May 31, 2019
1 parent 4d485aa commit 4ba6be6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -12,6 +12,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
* Fix crash when changing canvas width/height while `fillStyle` or `strokeStyle`
was set to a `CanvasPattern` or `CanvasGradient` (#1357).
* Fix crash when changing width/height of SVG canvases (#1380).

2.5.0
==================
Expand Down
10 changes: 8 additions & 2 deletions src/backend/SvgBackend.cc
Expand Up @@ -3,6 +3,7 @@
#include <cairo-svg.h>
#include "../Canvas.h"
#include "../closure.h"
#include <cassert>

using namespace v8;

Expand All @@ -13,7 +14,10 @@ SvgBackend::SvgBackend(int width, int height)

SvgBackend::~SvgBackend() {
cairo_surface_finish(surface);
if (_closure) delete _closure;
if (_closure) {
delete _closure;
_closure = nullptr;
}
destroySurface();
}

Expand All @@ -22,14 +26,16 @@ Backend *SvgBackend::construct(int width, int height){
}

cairo_surface_t* SvgBackend::createSurface() {
if (!_closure) _closure = new PdfSvgClosure(canvas);
assert(!_closure);
_closure = new PdfSvgClosure(canvas);
surface = cairo_svg_surface_create_for_stream(PdfSvgClosure::writeVec, _closure, width, height);
return surface;
}

cairo_surface_t* SvgBackend::recreateSurface() {
cairo_surface_finish(surface);
delete _closure;
_closure = nullptr;
cairo_surface_destroy(surface);

return createSurface();
Expand Down
5 changes: 5 additions & 0 deletions test/canvas.test.js
Expand Up @@ -392,6 +392,11 @@ describe('Canvas', function () {
})
});

it('SVG Canvas#width changes don\'t crash (#1380)', function () {
const myCanvas = createCanvas(100, 100, 'svg')
myCanvas.width = 120;
});

it('Canvas#stride', function() {
var canvas = createCanvas(24, 10);
assert.ok(canvas.stride >= 24, 'canvas.stride is too short');
Expand Down

0 comments on commit 4ba6be6

Please sign in to comment.