MessageDialog properties vanish the second time it's triggered

I am triggering a message dialog with the following code:

        let errorDialog = ui.builder.getMessageDialog("error_msg_dialog")
        discard errorDialog.run()
        errorDialog.destroy()

Video of reproducing the error: https://streamable.com/737443

When triggered the first time, everything seems to work well (except for that suspicious lack of vertical borders around the “Ok” button). When triggered the second time, all properties are lost. What could be causing this?


Relevant glade:

<object class="GtkMessageDialog" id="error_msg_dialog">
    <property name="can-focus">False</property>
    <property name="has-focus">True</property>
    <property name="is-focus">True</property>
    <property name="title" translatable="yes">Invoicer</property>
    <property name="resizable">False</property>
    <property name="modal">True</property>
    <property name="window-position">center-on-parent</property>
    <property name="icon-name">dialog-warning-symbolic</property>
    <property name="type-hint">dialog</property>
    <property name="transient-for">app_window</property>
    <property name="attached-to">popover</property>
    <property name="message-type">error</property>
    <property name="buttons">ok</property>
    <property name="text" translatable="yes">Invalid Input</property>
    <property name="secondary-text" translatable="yes">Please review your inputs and try again</property>
    <child internal-child="vbox">
      <object class="GtkBox">
        <property name="can-focus">False</property>
        <property name="orientation">vertical</property>
        <property name="spacing">5</property>
        <child internal-child="action_area">
          <object class="GtkButtonBox">
            <property name="can-focus">False</property>
            <property name="homogeneous">True</property>
            <property name="layout-style">center</property>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">False</property>
            <property name="position">0</property>
          </packing>
        </child>
      </object>
    </child>
  </object>

Does that occur only with the Nim bindings, or with plain C and Rust bindings as well?

Compiled with default refc GC or with ARC/ORC. For refc GC you may try to disable GC with GC_disable(), but I do not assume that it would make a difference.

I could imagine an issue with destruction of the Nim proxy object and recreation for the next call, but unfortunately dialogs and glade/builder use is not much tested yet. Of course a minimal but complete test example code would help, in best case a Nim and a working C version :slight_smile:

Are you still coding in the fancy “immediate mode” style as in your first post?

https://forum.nim-lang.org/t/7212#45560

Hi @StefanSalewski,

Unfortunately I am have not tested it against other Gtk bindings, since I personally think this is not a bindings issue. This is compiled with the default GC shipped with nim v1.4.2.

The full code is available here https://gitlab.com/9898287/invoicer (See the doneButtonEvent in frontend/ui.nim), to run you just issue $nimble run in the project root.

Are you still coding in the fancy “immediate mode” style as in your first post?

No. But that remained a mystery to me. I ended up trying to reproduce it in Gtk-rs and it would not crash and then I halfhazardly put together the rest of the code to complete the project: https://gitlab.com/9898287/timediff. That style seems to work. But I am not messing with any glib timeout here (yet :smiley: )

Yes, but to get help here it really helps to prove that an issue is really not a binding issue. I generally try to provide plain C code examples. And it makes testing for gtk core devs easier. But indeed I can not really imagine how it may be a bindings issue, as long as you follow general coding styles and not try such immediate mode tricks. I will try to look at your code in the next days when it is not too large…

You are literally destroying the instance created by GtkBuilder. You will either need to re-create it, by parsing the UI file again; or you will need to use hide() instead of destroy().

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.