Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Setting an empty ListStore as TreeView's model causes crash when headers are visible #701

Closed
ghost opened this issue Sep 12, 2018 · 8 comments

Comments

@ghost
Copy link

ghost commented Sep 12, 2018

PS > cargo run
   Compiling qwerty v0.1.0 (file:///D:/Code/qwerty)
    Finished dev [unoptimized + debuginfo] target(s) in 6.62s
     Running `target\debug\qwerty.exe`
Assertion failed!

Program: D:\Code\qwerty\target\debug\qwerty.exe
File: ../../cairo-1.15.12/src/cairo-surface.c, Line 542

Expression: surface->is_clear
error: process didn't exit successfully: `target\debug\qwerty.exe` (exit code: 3)
extern crate gtk;

use gtk::prelude::*;
use gtk::{
    CellRendererText, ListStore, Orientation,
    TreeView, TreeViewColumn, Window, WindowType,
};

fn append_text_column(tree: &TreeView) {
    let column = TreeViewColumn::new();
    let cell = CellRendererText::new();
    column.pack_start(&cell, true);
    column.add_attribute(&cell, "text", 0);
    column.set_title("column");
    tree.append_column(&column);
}

fn main() {
    gtk::init().unwrap();
    let tree = TreeView::new();
    append_text_column(&tree);
    let store = ListStore::new(&[String::static_type()]);
    // Uncommenting any of these fixes the issue:
    // tree.set_headers_visible(false);
    // store.insert_with_values(None, &[0], &[&"qwerty"]);
    tree.set_model(Some(&store));
    let window = Window::new(WindowType::Toplevel);
    let box_ = gtk::Box::new(Orientation::Horizontal, 10);
    box_.set_size_request(-1, -1);
    box_.add(&tree);
    window.add(&box_);
    window.show_all();
    gtk::main();
}
[dependencies.gtk]
version = "0.5.0"
features = ["v3_10"]

PS: In my real code, calling store.clear() after initialization helps as well, still no idea why it doesn't work in this toy example.

@GuillaumeGomez
Copy link
Member

I think the problem lies below: directly in C libraries. Might be worth opening them an issue as well.

@ghost
Copy link
Author

ghost commented Sep 12, 2018

I think the problem lies below: directly in C libraries. Might be worth opening them an issue as well.

This functionality seems so basic and common that I was assuming it's not GTK problem, but you're right, I gonna check it tomorrow.

@GuillaumeGomez
Copy link
Member

Thanks! I really hope the problem is coming from gtk-rs but I'm afraid it's not... Waiting to hear back from you!

@ghost
Copy link
Author

ghost commented Sep 13, 2018

Thanks! I really hope the problem is coming from gtk-rs but I'm afraid it's not... Waiting to hear back from you!

@GuillaumeGomez You're right, this is GTK problem. C version:

#include <gtk/gtk.h>

enum { COL_NAME = 0, COL_AGE, NUM_COLS };

static GtkTreeModel *create_and_fill_model(void) {
    GtkListStore *store;
    store = gtk_list_store_new(NUM_COLS, G_TYPE_STRING, G_TYPE_UINT);
    // Uncommenting these fixes the issue:
    // GtkTreeIter iter;
    // gtk_list_store_append(store, &iter);
    // gtk_list_store_set(store, &iter, COL_NAME, "Heinz", COL_AGE, 51, -1);
    return GTK_TREE_MODEL(store);
}

static GtkWidget *create_view_and_model(void) {
    GtkCellRenderer *renderer;
    GtkTreeModel *model;
    GtkWidget *view;
    view = gtk_tree_view_new();
    renderer = gtk_cell_renderer_text_new();
    gtk_tree_view_insert_column_with_attributes(
        GTK_TREE_VIEW(view), -1, "Name", renderer, "text", COL_NAME, NULL);
    renderer = gtk_cell_renderer_text_new();
    gtk_tree_view_insert_column_with_attributes(
        GTK_TREE_VIEW(view), -1, "Age", renderer, "text", COL_AGE, NULL);
    model = create_and_fill_model();
    gtk_tree_view_set_model(GTK_TREE_VIEW(view), model);
    g_object_unref(model);
    return view;
}

int main(int argc, char **argv) {
    GtkWidget *window;
    GtkWidget *view;
    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    g_signal_connect(window, "delete_event", gtk_main_quit, NULL);
    view = create_view_and_model();
    gtk_container_add(GTK_CONTAINER(window), view);
    gtk_widget_show_all(window);
    gtk_main();
    return 0;
}

@ghost ghost closed this as completed Sep 13, 2018
@GuillaumeGomez
Copy link
Member

Can you link here the gtk issue when it's open please?

@ghost
Copy link
Author

ghost commented Sep 13, 2018

Can you link here the gtk issue when it's open please?

Sure.

@ghost
Copy link
Author

ghost commented Sep 13, 2018

@GuillaumeGomez
Copy link
Member

Thanks!

alex179ohm pushed a commit to alex179ohm/gtk that referenced this issue Oct 21, 2019
Fix unstable super_calback's list for g_vfs_register_uri_scheme
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant