1

I'm trying to create an application with GtkAda and need the user to select a file from his PC. However, I found no way to create a file chooser without leading to this error: raised PROGRAM_ERROR : unhandled signal.

Using Glade 3.22.1

I tried creating a file chooser button and link it to a file chooser dialog. It leads to the same error.


Without Glade

I tried creating a file chooser dialog and file chooser button in GPS but same error.

Then I found the Gtkada.File_Selection package. Its description says it handles himself the signals and only needs a single function. Sadly, it leads to the same fateful error.

I'm working on Fedora 29. GtkAda version 2018, GPS 2018 and GNAT 8.3.1.

Log_Filter_Handlers.ads

with Gtkada.File_Selection;   use Gtkada.File_Selection;

package Log_Filter_Handlers is

   Retour : Unbounded_String;


   procedure Button_Select_File_Clicked
     (Self : access Gtk_Button_Record'Class);

end Log_Filter_Handlers;

Log_Filter_Handlers.adb

   procedure Button_Select_File_Clicked
     (Self : access Gtk_Button_Record'Class) is

   begin

      Retour := To_Unbounded_String
        (File_Selection_Dialog (Title       => "Select your file",
                                Default_Dir => "",
                                Dir_Only    => False,
                                Must_Exist  => True) );

   end Button_Select_File_Clicked;

Gtkada-File_Selection.ads

package Gtkada.File_Selection is

function File_Selection_Dialog

      (Title       : Glib.UTF8_String := "Select File";
      Default_Dir : String := "";
      Dir_Only    : Boolean := False;
      Must_Exist  : Boolean := False) return String;

end Gtkada.File_Selection;

As soon as the application creates a file chooser widget (be it dialog or button), in this case by calling Button_Select_File_Clicked. It immediately leads to this error: raised PROGRAM_ERROR : unhandled signal

I'm having some warnings too

Gtk-Message: 10:43:33.615: Failed to load module "pk-gtk-module"

Gtk-Message: 10:43:33.615: Failed to load module "canberra-gtk-module"

Gtk-Message: 10:43:33.616: Failed to load module "pk-gtk-module"

Gtk-Message: 10:43:33.616: Failed to load module "canberra-gtk-module"

Fontconfig warning: "/home/bob/Applications/Gnat_IDE/Gnat-community/etc/fonts/fonts.conf", line 86: unknown element "blank"

(log_filter_main:24417): Gtk-WARNING **: 10:43:33.841: Could not load a pixbuf from icon theme.

This may indicate that pixbuf loaders or the mime database could not be found.

Thank you.

  • Sounds like an incomplete GTK installation (or two mutually incompatible ones) can you check if you have canberra and pk installed and at the same version you are compiling for? –  Jul 26 '19 at 15:55
  • `PackageKit-gtk3-module-1.1.12-2.fc29.x86_64`. `libcanberra-0.30-17.fc29.x86_64`. Canberra isn't a problem anymore, I solved it by updating ldconfig. However, libpk keeps leading to warnings. I can't find libpk-gtk3-module.so in the gtk-3.0/modules folder. Could it be the reason for the warnings? `ls /usr/lib64/gtk-3.0/modules` `libcanberra-gtk3-module.so libcanberra-gtk-module.so libpk-gtk-module.so` – Lyaaaaaaaaaaaaaaa Jul 29 '19 at 07:37

1 Answers1

2

It's hard to say what causes the unhandled signal error. You could consider making a stack trace to see where the exception is raised (see also the example on Rosetta code).

The example below works on GNAT CE 2019. You could test it in your own environment to see if the problem persists, or test your own code with latest version of GtkAda found on GitHub.


Update

A quick search reveals that a Program_Error with message "unhandled signal" is never raised from GtkAda. In fact, it seems that this kind of exception can only occur in the GNAT/Ada run-time (see init.c and seh_init.c). And while seh_init.c is used only by the run-times targeting Win32 and Cygwin (see comments near the beginning of that file), init.c, is used in various other run-times including the one for Linux. Hence, I think that the Program_Error you observe is raised in init.c because some kernel signal cannot be handled by the GNAT/Ada run-time.

You might obtain some additional information by tracing the signals send to your application (see also this post on SO):

strace -e 'trace=!all' <program_name>

main.adb

with File_Selection_Demo;

procedure Main is
begin
   File_Selection_Demo.Run;
end Main;

file_selection_demo.ads

package File_Selection_Demo is

   procedure Run;

end File_Selection_Demo;

file_selection_demo.adb

with Ada.Text_IO;

with Gtk.Main;
with Gtk.Widget;
with Gtk.Builder;
with Gtk.Window;
with Gtk.Button;
with Gtk.GEntry;

with Gtkada.File_Selection;

with Glib;       use Glib;
with Glib.Error; use Glib.Error;

package body File_Selection_Demo is

   --  Widgets
   Builder : Gtk.Builder.Gtk_Builder;
   Window  : Gtk.Window.Gtk_Window;
   Button  : Gtk.Button.Gtk_Button;
   GEntry  : Gtk.GEntry.Gtk_Entry;


   procedure Destroy_Event_Callback
     (Widget : access Gtk.Widget.Gtk_Widget_Record'Class);

   procedure Clicked_Event_Callback
     (Button : access Gtk.Button.Gtk_Button_Record'Class);


   ---------
   -- Run --
   ---------

   procedure Run is

      use Gtk.Builder;
      use Gtk.Window;
      use Gtk.Button;
      use Gtk.GEntry;

      Success : GUint;
      Error   : aliased GError;

   begin

      --  Initialize GtkAda.
      Gtk.Main.Init;

      -- Construct a Gtk_Builder instance and load our UI description.
      Gtk_New (Builder);

      Success := Builder.Add_From_File ("./example.glade", Error'Access);
      if Success = 0 then
         Ada.Text_IO.Put_Line ("failed to read Glade file");
         Error_Free (Error);         
         return;
      end if;

      --  Entry
      GEntry := Gtk_Entry (Builder.Get_Object ("Entry"));

      --  Button
      Button := Gtk_Button (Builder.Get_Object ("Button"));
      Button.On_Clicked (Clicked_Event_Callback'Access);

      -- Window
      Window := Gtk_Window (Builder.Get_Object ("Window"));
      Window.On_Destroy (Destroy_Event_Callback'Access);
      Window.Show_All;

      -- Start the main event loop
      Gtk.Main.Main;

   end Run;


   ----------------------------
   -- Destroy_Event_Callback --
   ----------------------------

   procedure Destroy_Event_Callback
     (Widget : access Gtk.Widget.Gtk_Widget_Record'Class)
   is
   begin
      Gtk.Main.Main_Quit;
   end Destroy_Event_Callback;

   ----------------------------
   -- Clicked_Event_Callback --
   ----------------------------

   procedure Clicked_Event_Callback
     (Button : access Gtk.Button.Gtk_Button_Record'Class) is
   begin

      declare
         Response : String :=
                      Gtkada.File_Selection.File_Selection_Dialog
                        (Title       => "Select your file",
                         Default_Dir => "",
                         Dir_Only    => False,
                         Must_Exist  => True);
      begin
         GEntry.Set_Text (Response);
      end;

   end Clicked_Event_Callback;

end File_Selection_Demo;

example.glade

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.16.1 -->
<interface>
  <requires lib="gtk+" version="3.10"/>
  <object class="GtkWindow" id="Window">
    <property name="can_focus">False</property>
    <property name="title" translatable="yes">GTK File Selector Demo</property>
    <property name="resizable">False</property>
    <property name="window_position">center</property>
    <child>
      <object class="GtkBox" id="HBox">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <child>
          <object class="GtkEntry" id="Entry">
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="margin_left">10</property>
            <property name="margin_right">10</property>
            <property name="margin_top">5</property>
            <property name="margin_bottom">5</property>
            <property name="hexpand">True</property>
            <property name="editable">False</property>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="position">0</property>
          </packing>
        </child>
        <child>
          <object class="GtkButton" id="Button">
            <property name="label" translatable="yes">Choose File...</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="receives_default">True</property>
            <property name="margin_left">10</property>
            <property name="margin_right">12</property>
            <property name="margin_top">5</property>
            <property name="margin_bottom">5</property>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="position">1</property>
          </packing>
        </child>
      </object>
    </child>
  </object>
</interface>
DeeDee
  • 5,654
  • 7
  • 14
  • The particular ```Program_Error``` is most likely caused by an unhandled *kernel* signal. See updated answer. – DeeDee Jul 11 '19 at 17:53
  • Here is the strace output when I'm raising the error `strace: Process 12811 attached --- SIGABRT {si_signo=SIGABRT, si_code=SI_TKILL, si_pid=12811, si_uid=1000} ---` – Lyaaaaaaaaaaaaaaa Jul 12 '19 at 10:17
  • The result is the same for both your example and my code. – Lyaaaaaaaaaaaaaaa Jul 12 '19 at 10:28
  • Same result with Gtkada 2019 and Gnat 2019. – Lyaaaaaaaaaaaaaaa Jul 12 '19 at 11:14
  • The `SIGABRT` signal might be due to a fatal error within `libc` (see [here](https://stackoverflow.com/q/3413166)). You might be able to verify this (see [here](https://stackoverflow.com/a/32056388)), but it’s unlikely that this will lead you to a solution. I’m guessing here, but there might be a library version conflict. Could you check which version of GTK is installed? On Fedora, I think you can do this via `rpm -q gtk2` and/or `rpm -q gtk3`. – DeeDee Jul 12 '19 at 11:37
  • Gtk3: `gtk3-3.24.1-3.fc29.x86_64`. Gtk 2: `gtk2-2.24.32-4.fc29.x86_64`. Both installed on my PC. – Lyaaaaaaaaaaaaaaa Jul 12 '19 at 13:56
  • The readme file of the GtkAda repository on GitHub states that the latest version of the library has been tested with Gtk+ 3.14.15. However, the discrepancy between Gtk+ 3.14.15 and the version installed on your system, 3.24.1, does not necessarily have to be the root cause of the problem you observe. Based on the (last) warning, I suspect that the problem is actually related to the current GTK+ runtime and theme installation/configuration itself, and in particular to (the configuration of) `gdk-pixbuf` (but I'm not certain). – DeeDee Jul 13 '19 at 09:04
  • There might also be a problem with the permissions on files in `/usr/share/mime` (see [this](https://unix.stackexchange.com/q/505063) post on SO). – DeeDee Jul 13 '19 at 11:24
  • Permissions seem okay, the mimes' files are in 644. – Lyaaaaaaaaaaaaaaa Jul 15 '19 at 07:37
  • ...and I assume that reinstalling the packages `pk-gtk-module` and `canberra-gtk-module` (as suggested in [this](https://askubuntu.com/q/342202) and [this](https://askubuntu.com/q/208431) post on SO) or adding a path to the `LD_LIBRARY_PATH` environment variable (as proposed in [this](https://askubuntu.com/a/944202) answer on SO) also don't work (posts are for Ubuntu, but the solutions might also work for Fedora). – DeeDee Jul 15 '19 at 08:28
  • The 'pk-gtk-module' is no longer a problem. I updated the 'ldconfig' after creating a 'gtk3.conf' in ld.so.conf.d. The gtk3.conf contains '/usr/lib64/gtk-3.0/modules'. Sadly the 'canberra-gtk-module' keeps not loading. Btw, is 'LD_LIBRARY_PATH' and 'ldconfig' the same? – Lyaaaaaaaaaaaaaaa Jul 15 '19 at 10:22
  • I believe that, in this case, configuring `ld.so.cache` or using `LD_LIBRARY_PATH` has the same effect (based on the section "Description" in [ld.so(8)](http://man7.org/linux/man-pages/man8/ld.so.8.html)). You might also try to set the environment variables `GTK3_MODULES=canberra-gtk-module` (or `GTK_MODULES=canberra-gtk-module`) as suggested in the [GNOME developer documentation](https://developer.gnome.org/gtk3/stable/gtk-running.html). – DeeDee Jul 15 '19 at 10:39
  • I built the project with 'Gprbuild' and tried to run the program from my terminal. It surprisingly worked. My program and yours open the file dialogue. I don't understand why. Therefore, I'm not stuck, however, It would be easier to test directly from GPS. The problem remains but is less critical! – Lyaaaaaaaaaaaaaaa Jul 15 '19 at 13:17
  • Great to hear! So GPS itself might be interfering with the application under development. GPS does seem to use some local GTK runtime libraries located in `/lib/gps` (checked using `ldd ./gps_exe`). Maybe this is the reason that unexpected things might happen when the application under development is run in a (spawned) child process. Who knows. Anyway, thanks for the feedback! – DeeDee Jul 15 '19 at 13:49