Gtkmm4-17-4 Gtk:ERROR:../subprojects/gtk/gtk/gtktextlinedisplaycache.c:786:gtk_text_line_display_cache_set_cursor_line: assertion failed: (cache != NULL)

Bail out! Gtk:ERROR:../subprojects/gtk/gtk/gtktextlinedisplaycache.c:786:gtk_text_line_display_cache_set_cursor_line: assertion failed: (cache != NULL)

I will give more detail later - sorry
This happen randomly when closing a window with delete
On Debian, C++
I try to delete the window resource from memory, not just put it invisible
→ how do we delete window in gtkmm4?

void gui_mgr::del_window(int n, bool force)
{
	// delay/asynchrone manner
	std::thread t(&gui_mgr::delayed_delete, this, n);
        t.detach(); // Detach the thread so it runs independently
}

void gui_mgr::delayed_delete(int n) 
{
    std::this_thread::sleep_for(std::chrono::seconds(3)); // delay

    std::lock_guard<std::mutex> lock(gui_mutex_); // LOCK
    if (vwindow.contains(n))
    {
	Gtk::Window* p = vwindow[n]; //std::map
        if (p!=nullptr)
        {
	       delete p;
        } 
	vwindow[n] = nullptr;         
        vwindow.erase(n);
    }
}

void on_button_quit()
{
    gui_mgr* gg = gui_mgr::get_instance("");
    gg->del_window(this->_window_number, true);
}

class checkkeys_window : public Gtk::Window
{
...
}

checkkeys_window* window = new checkkeys_window(..) ;
gui_mgr* gg = gui_mgr::get_instance("");
window->_window_number = gg->window_counter;
gg->add_window(window, gg->window_counter);
gg->window_counter++;

Note: deleting directly from same thread with a delay seem to help [not ideal]

void gui_mgr::del_window(int n, bool force)
{
    delayed_delete(n);
    return;
}

Hello @alainalain,

are you using GTK from different threads? That’s not supported, even when using a mutex to serialize calls. That’s because GTK can read and write to its own data structures at any time, independently of your code. That happens when GdkFrameClock starts a paint phase to draw animations, or even when sourcing events from the windowing system.

In order to delay something, try adding an idle callback with GLib.idle_add_once