Fix gtk_widget_destroy warnings

gtk_remove_widget unrefs the widget and destroys it and all its children.
Since we also do that in the destructor, we do a double free.
To fix this, a ref is added to prevent destroying by gtk_remove_widget.
This commit is contained in:
scorpion-26 2023-11-05 22:01:09 +01:00
parent f0d3c6c0e4
commit eb8e0bc2b5

View file

@ -47,9 +47,12 @@ namespace Utils
Widget::~Widget()
{
m_Childs.clear();
LOG("Destroy widget");
gtk_widget_destroy(m_Widget);
if (m_Widget)
{
LOG("Destroy widget and its children");
m_Childs.clear();
gtk_widget_destroy(m_Widget);
}
}
void Widget::CreateAndAddWidget(Widget* widget, GtkWidget* parentWidget)
@ -144,8 +147,10 @@ void Widget::RemoveChild(Widget* widget)
{
if (m_Widget)
{
LOG("Remove widget from parent");
// Ref the widget, so we don't mess up the RAII cleanup below
g_object_ref(it->get()->m_Widget);
gtk_container_remove((GtkContainer*)m_Widget, it->get()->m_Widget);
it->get()->m_Widget = nullptr;
}
m_Childs.erase(it);
}