hotfix: fix panic because of deallocated GTK widget being called in handler (fixes #478)
This commit is contained in:
parent
d8bb8c4142
commit
aac4c3aef4
1 changed files with 5 additions and 1 deletions
|
@ -43,9 +43,13 @@ macro_rules! def_widget {
|
||||||
crate::state::scope::Listener {
|
crate::state::scope::Listener {
|
||||||
needed_variables: required_vars,
|
needed_variables: required_vars,
|
||||||
f: Box::new({
|
f: Box::new({
|
||||||
|
// create a weak reference to the widget, such that this listener doesn't prevent the actual widget from
|
||||||
|
// getting deallocated (garbage collected by the gtk runtime)
|
||||||
let $gtk_widget = gdk::glib::clone::Downgrade::downgrade(&$gtk_widget);
|
let $gtk_widget = gdk::glib::clone::Downgrade::downgrade(&$gtk_widget);
|
||||||
move |$scope_graph, values| {
|
move |$scope_graph, values| {
|
||||||
let $gtk_widget = gdk::glib::clone::Upgrade::upgrade(&$gtk_widget).unwrap();
|
// TODO when this fails, shouldn't we technically remove the listener somehow? Need to analyze when exactly this happens.
|
||||||
|
let $gtk_widget = gdk::glib::clone::Upgrade::upgrade(&$gtk_widget)
|
||||||
|
.context("Couldn't upgrade reference, widget got deallocated")?;
|
||||||
// values is a map of all the variables that are required to evaluate the
|
// values is a map of all the variables that are required to evaluate the
|
||||||
// attributes expression.
|
// attributes expression.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue