Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thorvg: terminate engine properly. #101

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions dotlottie-rs/src/thorvg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,25 @@ pub trait Drawable {

pub struct Canvas {
raw_canvas: *mut Tvg_Canvas,
engine_method: Tvg_Engine
}

impl Canvas {
pub fn new(engine_method: TvgEngine, threads: u32) -> Self {
let engine_method = match engine_method {
let engine = match engine_method {
TvgEngine::TvgEngineSw => Tvg_Engine_TVG_ENGINE_SW,
TvgEngine::TvgEngineGl => Tvg_Engine_TVG_ENGINE_GL,
};

let init_result = unsafe { tvg_engine_init(engine_method, threads) };
let init_result = unsafe { tvg_engine_init(engine, threads) };

if init_result != Tvg_Result_TVG_RESULT_SUCCESS {
panic!("Failed to initialize ThorVG engine");
}

Canvas {
raw_canvas: unsafe { tvg_swcanvas_create() },
engine_method: engine
}
}

Expand Down Expand Up @@ -154,8 +156,8 @@ impl Canvas {
impl Drop for Canvas {
fn drop(&mut self) {
unsafe {
tvg_canvas_clear(self.raw_canvas, true);
tvg_canvas_destroy(self.raw_canvas);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would tvg_canvas_destroy free the pushed paints from memory ? or do we still to manually free it in this case ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, if the canvas retains the paints, it will delete them.

tvg_engine_term(self.engine_method);
};
}
}
Expand Down
Loading