Skip to content

Commit

Permalink
Throw surface errors in toBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfedr committed Jul 18, 2024
1 parent 83a5126 commit 960e2f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
==================
### Changed
### Added
* Throw errors in canvas
### Fixed


Expand Down
10 changes: 9 additions & 1 deletion src/Canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,15 @@ Canvas::ToBuffer(const Napi::CallbackInfo& info) {
closure = static_cast<SvgBackend*>(backend())->closure();
}

cairo_surface_finish(surface());
cairo_surface_t *surf = surface();
cairo_surface_finish(surf);

cairo_status_t status = cairo_surface_status(surf);
if (status != CAIRO_STATUS_SUCCESS) {
Napi::Error::New(env, cairo_status_to_string(status)).ThrowAsJavaScriptException();
return env.Undefined();
}

return Napi::Buffer<uint8_t>::Copy(env, &closure->vec[0], closure->vec.size());
}

Expand Down

0 comments on commit 960e2f3

Please sign in to comment.