From ea44732a1e5ce5139801b02ad96319c3662d7fdd Mon Sep 17 00:00:00 2001 From: Abdelrahman Ashraf Date: Mon, 4 Mar 2024 21:11:24 +0700 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20segmentation=20fault=20wh?= =?UTF-8?q?en=20LottieRender=20is=20dropped=20(#91)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: 🤖 replicate the issue * fix: 🐛 call tvg_animation_del on drop --- demo-player/src/main.rs | 16 +++++++++++++--- dotlottie-rs/src/thorvg.rs | 7 +++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/demo-player/src/main.rs b/demo-player/src/main.rs index 6a49edf4..b370d8b7 100644 --- a/demo-player/src/main.rs +++ b/demo-player/src/main.rs @@ -218,11 +218,21 @@ fn main() { } } - if window.is_key_down(Key::L) { - lottie_player.load_animation_data(string.as_str(), WIDTH as u32, HEIGHT as u32); + if window.is_key_pressed(Key::L, KeyRepeat::No) { + lottie_player = DotLottiePlayer::new(Config { + mode: Mode::ReverseBounce, + loop_animation: true, + speed: 1.0, + use_frame_interpolation: true, + autoplay: true, + segments: vec![10.0, 45.0], + background_color: 0xffffffff, + }); + + lottie_player.load_animation_data(&string, WIDTH as u32, HEIGHT as u32); } - if window.is_key_down(Key::R) { + if window.is_key_pressed(Key::R, KeyRepeat::No) { lottie_player.load_dotlottie_data(&buffer, WIDTH as u32, HEIGHT as u32); } diff --git a/dotlottie-rs/src/thorvg.rs b/dotlottie-rs/src/thorvg.rs index 28d80623..2cf439ce 100644 --- a/dotlottie-rs/src/thorvg.rs +++ b/dotlottie-rs/src/thorvg.rs @@ -149,7 +149,10 @@ impl Canvas { impl Drop for Canvas { fn drop(&mut self) { - unsafe { tvg_canvas_destroy(self.raw_canvas) }; + unsafe { + tvg_canvas_clear(self.raw_canvas, true); + tvg_canvas_destroy(self.raw_canvas); + }; } } @@ -281,7 +284,7 @@ impl Drawable for Animation { impl Drop for Animation { fn drop(&mut self) { unsafe { - tvg_paint_del(self.raw_paint); + tvg_animation_del(self.raw_animation); }; } }