mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 14:21:16 +00:00
Avoid possible leaks when loading html images and then destroying the window
Keep weak references to the canvas, etc. for the DOM closure
This commit is contained in:
parent
0b20d13401
commit
30bc16db73
1 changed files with 13 additions and 3 deletions
|
@ -367,12 +367,22 @@ impl GLItemRenderer {
|
||||||
html_image.set_cross_origin(Some("anonymous"));
|
html_image.set_cross_origin(Some("anonymous"));
|
||||||
html_image.set_onload(Some(
|
html_image.set_onload(Some(
|
||||||
&wasm_bindgen::closure::Closure::once_into_js({
|
&wasm_bindgen::closure::Closure::once_into_js({
|
||||||
let canvas = self.canvas.clone();
|
let canvas_weak = Rc::downgrade(&self.canvas);
|
||||||
let html_image = html_image.clone();
|
let html_image = html_image.clone();
|
||||||
let image_id = image_id.clone();
|
let image_id = image_id.clone();
|
||||||
let window = self.window.clone();
|
let window_weak = Rc::downgrade(&self.window);
|
||||||
let event_loop_proxy = self.event_loop_proxy.clone();
|
let event_loop_proxy_weak = Rc::downgrade(&self.event_loop_proxy);
|
||||||
move || {
|
move || {
|
||||||
|
let (canvas, window, event_loop_proxy) = match (
|
||||||
|
canvas_weak.upgrade(),
|
||||||
|
window_weak.upgrade(),
|
||||||
|
event_loop_proxy_weak.upgrade(),
|
||||||
|
) {
|
||||||
|
(Some(canvas), Some(window), Some(event_loop_proxy)) => {
|
||||||
|
(canvas, window, event_loop_proxy)
|
||||||
|
}
|
||||||
|
_ => return,
|
||||||
|
};
|
||||||
canvas
|
canvas
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.realloc_image(
|
.realloc_image(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue