gtkd-developers / GtkD

GtkD is a D binding and OO wrapper of GTK+ originally created by Antonio Monteiro
http://gtkd.org
Other
320 stars 71 forks source link

app crash after reported : GLib-GObject-WARNING **: g_object_remove_toggle_ref: couldn't find toggle ref #239

Closed dangbinghoo closed 6 years ago

dangbinghoo commented 6 years ago

I think it's a related issue as the #220

I wrote a small program which read some data from database, and listed them on a gtk listview. the program need to refresh the list every time when it's container tab is closed. so I have a very simple logic, just clear the datastore before I read out data from database, then for each data row, create a iter and set value.

The program may crash after several clicking for loading the list data before I was using gtkd 3.7.x , but today I upgraded to gtkd 3.8.0, it crashed immediately when I did a second click for loading the data.

here is the code

void uiLoadTabToolCatalog(ref UI ui)
{
    writeln("Loading All Tool type and spec info from DB....");
     ui.listToolCatalogStore.clear();
    auto em = DBM.getEntityManager();
    CriteriaBuilder criteria = em.createCriteriaBuilder!DBMToolCatalog;
    DBMToolCatalog[] tools = em.getResultList!DBMToolCatalog(criteria);

    auto em2 = DBM.getEntityManager();
    CriteriaBuilder cb = em2.createCriteriaBuilder!DBMToolType;
    DBMToolType[] types = em2.getResultList!DBMToolType(cb);

    ToolID toolID;

    foreach (t; tools) {
        if (t is null) {
            continue;
        }
        TreeIter iter = ui.listToolCatalogStore.createIter();
        ui.listToolCatalogStore.setValue(iter, TOOLCATALOG_COL1, t.date);
        ui.listToolCatalogStore.setValue(iter, TOOLCATALOG_COL2, t.currepc);
        //writefln("toolepc %s tool %s --> ", t.currepc, t.typestr);

        if (strToToolID(t.currepc, toolID) == 0) {
            string tooltypeHex = format("%04X", toolID.types);
            //writefln("tool type hexstr %s", tooltypeHex);
            if (types.length > 0) {
                foreach (ty; types) {
                    if (ty.typehex == tooltypeHex) {
                        //writefln("tool icon = %s", ty.iconid);
                        // if (!(ty.iconid is null)) {
                        //     ui.listToolCatalogStore.setValue(iter, TOOLCATALOG_COL3, new Pixbuf("./res/" ~ ty.iconid ~ ".png", 30, 30));
                        // }   
                    }
                }
            }
        }

        ui.listToolCatalogStore.setValue(iter, TOOLCATALOG_COL4, t.typestr);
        ui.listToolCatalogStore.setValue(iter, TOOLCATALOG_COL5, t.specstr);
        ui.listToolCatalogStore.setValue(iter, TOOLCATALOG_COL6, t.customer);
        ui.listToolCatalogStore.setValue(iter, TOOLCATALOG_COL7, t.annote);
        ui.listToolCatalogStore.setValue(iter, TOOLCATALOG_COL8, t.tid);
    }
}

ui is a ref to the gtk application class.

/**
 * All ui elements.
 */
class UI 
{
    // UI elements.
    private ApplicationWindow parent;
    private Builder builder;

    //main Notebook
    public Notebook mainTabs;

    // tool catalog list
    public TreeView listToolCatalogBox;    //tool_catalog_list;
    public ListStore listToolCatalogStore;

    this (ApplicationWindow parent)
    {
        this.parent = parent;
    }

    auto getParent()
    {
        return this.parent;
    }

    auto el(T) (string idstr) {
        return cast(T) builder.getObject(idstr);
    }

    void setBuilder(Builder build){
        this.builder = build;
    }

    UI getSelf()
    {
        return this;
    }
}

and the crash happend after the following console output:


(RfidPCTool.exe:43156): GLib-GObject-WARNING **: g_object_remove_toggle_ref: couldn't find toggle ref 00007ff7a19804a0(000001f1d6663a40)

(RfidPCTool.exe:43156): GLib-GObject-WARNING **: g_object_remove_toggle_ref: couldn't find toggle ref 00007ff7a19804a0(000001f1d6663a80)

(RfidPCTool.exe:43156): GLib-GObject-WARNING **: g_object_remove_toggle_ref: couldn't find toggle ref 00007ff7a19804a0(000001f1d6663ac0)

(RfidPCTool.exe:43156): GLib-GObject-WARNING **: g_object_remove_toggle_ref: couldn't find toggle ref 00007ff7a19804a0(000001f1d6663b00)

(RfidPCTool.exe:43156): GLib-GObject-WARNING **: g_object_remove_toggle_ref: couldn't find toggle ref 00007ff7a19804a0(000001f1d6663b40)

(RfidPCTool.exe:43156): GLib-GObject-WARNING **: g_object_remove_toggle_ref: couldn't find toggle ref 00007ff7a19804a0(000001f1d6663b60)

(RfidPCTool.exe:43156): GLib-GObject-WARNING **: g_object_remove_toggle_ref: couldn't find toggle ref 00007ff7a19804a0(000001f1d6663ba0)

(RfidPCTool.exe:43156): GLib-GObject-WARNING **: g_object_remove_toggle_ref: couldn't find toggle ref 00007ff7a19804a0(000001f1d6663be0)

(RfidPCTool.exe:43156): GLib-GObject-WARNING **: g_object_remove_toggle_ref: couldn't find toggle ref 00007ff7a19804a0(000001f1d6663c20)

(RfidPCTool.exe:43156): GLib-GObject-WARNING **: g_object_remove_toggle_ref: couldn't find toggle ref 00007ff7a19804a0(000001f1d6663c40)

........

and in another tab in my app, a single line data store item remove will cause the application some time crash too.

    for (ui.listTagStore.getIterFirst(iter), iter.setModel(ui.listTagStore);
         ui.listTagStore.iterIsValid(iter); 
         ui.listTagStore.iterNext(iter)) {
        if (iter.getValueInt(TAGLIST_COL3)) {

                //some other code not related to the ui.

                //ui.listTagBox.select();
                ui.listTagStore.remove(iter);
        }
   }
MikeWey commented 6 years ago

Could you check if the issue is fixed with the changes from: e69ae0500282a85d066a709ceee699f06a3b6b05

dangbinghoo commented 6 years ago

hi, MikeWey,

I just tested the ~master version, the output is just different, and app crash situation is better, but it still crashes.

the log is :

$dub run
Non-selected package inifiled is available with version 1.0.2.
Non-selected package serial-port is available with version 1.2.0.
Use "dub upgrade" to perform those changes.
WARNING: A deprecated branch based version specification is used for the dependency gtk-d. Please use numbered versions instead. Also note that you can still use the dub.selections.json file to override a certain dependency to use a branch instead.
Performing "debug" build using /usr/bin/dmd for x86_64.
database 0.1.0: target for configuration "sqlite" is up to date.
entity 1.2.1: target for configuration "sqlite" is up to date.
gtk-d:gtkd ~master: target for configuration "library" is up to date.
gtk-d:gstreamer ~master: target for configuration "library" is up to date.
gtk-d:peas ~master: target for configuration "library" is up to date.
gtk-d:sv ~master: target for configuration "library" is up to date.
gtk-d:vte ~master: target for configuration "library" is up to date.
rfidtool ~master: building configuration "windows"...
Linking...
To force a rebuild of up-to-date targets, run again with --force.
Running ./bin/RfidPCTool 
2018-04-16T10:44:40.508:app.d:main:16 Started app. 
2018-04-16T10:44:40.508:connection.d:this:78 Trying to open a sqlite file:/home/dbh/Desktop/gtk-rfid-app-code/bin/./RfidTools.db
2018-04-16T10:44:40.508:entitymanager.d:entityLog:244 ../../.dub/packages/entity-1.2.1/entity/source/entity/entitymanager.d:133 select * from tooltype;
2018-04-16T10:44:40.508:statement.d:execute:96 select * from tooltype; 
Loading All Tool type and spec info from DB....
2018-04-16T10:44:43.045:entitymanager.d:entityLog:244 ../../.dub/packages/entity-1.2.1/entity/source/entity/entitymanager.d:199  SELECT * FROM toolcatalog toolcatalog 
2018-04-16T10:44:43.046:connection.d:query:35  SELECT * FROM toolcatalog toolcatalog 
2018-04-16T10:44:43.050:entitymanager.d:entityLog:244 ../../.dub/packages/entity-1.2.1/entity/source/entity/entitymanager.d:199  SELECT * FROM tooltype tooltype 
2018-04-16T10:44:43.051:connection.d:query:35  SELECT * FROM tooltype tooltype 

(RfidPCTool:11088): GLib-GObject-CRITICAL **: g_value_set_pointer: assertion 'G_VALUE_HOLDS_POINTER (value)' failed

(RfidPCTool:11088): GLib-GObject-CRITICAL **: g_value_set_pointer: assertion 'G_VALUE_HOLDS_POINTER (value)' failed

(RfidPCTool:11088): GLib-GObject-CRITICAL **: g_value_set_pointer: assertion 'G_VALUE_HOLDS_POINTER (value)' failed

(RfidPCTool:11088): GLib-GObject-CRITICAL **: g_value_set_pointer: assertion 'G_VALUE_HOLDS_POINTER (value)' failed

(RfidPCTool:11088): GLib-GObject-CRITICAL **: g_value_set_pointer: assertion 'G_VALUE_HOLDS_POINTER (value)' failed

(RfidPCTool:11088): GLib-GObject-CRITICAL **: g_value_set_pointer: assertion 'G_VALUE_HOLDS_POINTER (value)' failed

(RfidPCTool:11088): GLib-GObject-CRITICAL **: g_value_set_pointer: assertion 'G_VALUE_HOLDS_POINTER (value)' failed
........
std.utf.UTFException@/usr/include/dmd/phobos/std/utf.d(1380): Invalid UTF-8 sequence (at index 1)
----------------
??:? pure dchar std.utf.decodeImpl!(true, 0, immutable(char)[]).decodeImpl(ref immutable(char)[], ref ulong) [0xfbe564cc]
??:? pure @trusted dchar std.utf.decode!(0, immutable(char)[]).decode(ref immutable(char)[], ref ulong) [0xfbe56444]
??:? pure @property @safe dchar std.range.primitives.front!(immutable(char)).front(immutable(char)[]) [0xfbe5637c]
??:? pure @property @safe dchar std.range.Take!(immutable(char)[]).Take.front() [0xfbe9dcb4]
??:? pure @safe ubyte std.conv.parse!(ubyte, std.range.Take!(immutable(char)[]).Take).parse(ref std.range.Take!(immutable(char)[]).Take, uint) [0xfbe9dfaf]
??:? pure @safe ubyte utils.hexStrToBytes(immutable(char)[]).__lambda2!(std.range.Take!(immutable(char)[]).Take).__lambda2(std.range.Take!(immutable(char)[]).Take) [0xfbeaaa69]
??:? pure @property @safe ubyte std.algorithm.iteration.MapResult!(utils.hexStrToBytes(immutable(char)[]).__lambda2, std.range.Chunks!(immutable(char)[]).Chunks).MapResult.front() [0xfbeaab72]
??:? pure @safe ubyte[] std.array.array!(std.algorithm.iteration.MapResult!(utils.hexStrToBytes(immutable(char)[]).__lambda2, std.range.Chunks!(immutable(char)[]).Chunks).MapResult).array(std.algorithm.iteration.MapResult!(utils.hexStrToBytes(immutable(char)[]).__lambda2, std.range.Chunks!(immutable(char)[]).Chunks).MapResult) [0xfbe9e591]
??:? ubyte[] utils.hexStrToBytes(immutable(char)[]) [0xfbeaa849]
??:? int toolidentify.strToToolID(const(immutable(char)[]), out toolidentify.ToolID) [0xfbeaa097]
??:? void appToolCatalog.uiLoadTabToolCatalog(ref ui.UI) [0xfbea08d4]
??:? void gtkapp.GTKApp.appUIMainPage().__dgliteral1(gtk.Widget.Widget, uint, gtk.Notebook.Notebook) [0xfbea663b]
??:? extern (C) void gobject.DClosure.DClosure.d_closure_marshal!(void delegate(gtk.Widget.Widget, uint, gtk.Notebook.Notebook)).d_closure_marshal(gobject.c.types.GClosure*, gobject.c.types.GValue*, uint,gobject.c.types.GValue*, void*, void*) [0xfc0b9be9]
??:? g_closure_invoke [0x5b1c8064]
Program exited with code 1

I don't know it is a gtkd problem or just bug in my code.

I just attach the related full code in a tarball in the attachment, gtk-rfid-app-code.tar.gz

dangbinghoo commented 6 years ago

I found the g_value_set_pointer: assertion 'G_VALUE_HOLDS_POINTER (value)' failed is just caused by

ui.listToolCatalogStore.setValue(iter, TOOLCATALOG_COL3, new Pixbuf("./res/tool_1.png", 20, 20));

But I don't know if there's any other way to display a icon in the list.

MikeWey commented 6 years ago

It looks like the recent changes to gobject.Value, are causing problems with the Pixbuf.