image_window: Don't rely on root existing

This fixes a single case of root being access from the control hide
animation. Apparently it's possible that the widget is unparented from
the window and unmaped but not yet unrefed?

Fixes #473
This commit is contained in:
Sophie Herold 2025-03-29 20:51:30 +01:00
parent 0b4db9e03f
commit 5055eddda0
3 changed files with 32 additions and 15 deletions

View file

@ -0,0 +1 @@
Crash when closing the window, probably in the exact moment when the animnation for hiding controls starts.

View file

@ -24,12 +24,28 @@ pub trait ParentWindow: WidgetExt {
let result = self.root().and_downcast();
if result.is_none() {
log::error!("Couldn't find LpWindow for {self:?}");
log::error!(
"Couldn't find LpWindow for {self:?}. mapped={}",
self.is_mapped()
);
}
result.unwrap()
}
fn try_window(&self) -> Option<LpWindow> {
let result = self.root().and_downcast();
if result.is_none() {
log::debug!(
"Couldn't find LpWindow for {self:?}. mapped={}",
self.is_mapped()
);
}
result
}
fn edit_window(&self) -> LpEditWindow {
let parent = self.parent().unwrap();

View file

@ -1,4 +1,4 @@
// Copyright (c) 2023-2024 Sophie Herold
// Copyright (c) 2023-2025 Sophie Herold
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@ -26,8 +26,7 @@ impl LpImageWindow {
/// Also changes headerbar transparency if it flat and hides/shows cursor on
/// fullscreen
fn set_control_opacity(&self, opacity: f64, hiding: bool) {
let window = self.window();
if let Some(window) = self.try_window() {
self.image_view().controls_box_start().set_opacity(opacity);
self.image_view().controls_box_end().set_opacity(opacity);
@ -43,6 +42,7 @@ impl LpImageWindow {
self.set_cursor(None);
}
}
}
pub fn controls_opacity(&self) -> f64 {
self.image_view().controls_box_start().opacity()