1

当我使用 gtkada 并且我的 GUI 正在运行时,不会管理任何异常并且程序总是崩溃。消息是

此应用程序已请求运行时以不寻常的方式终止它。

请联系应用程序的支持团队以获取更多信息。

一段测试代码如下:

    with GLib;          use GLib;
    with Gtk.Label;     use Gtk.Label;
    with Gtk.Window;    use Gtk.Window;
    with Gtk.Frame;     use Gtk.Frame;
    with Gtk.Button;    use Gtk.Button;
    with Gtk.Widget;    use Gtk.Widget;

    with Gtk.Handlers;
    with Gtk.Main;


    procedure gui_test_4 is
       Window          : Gtk_Window;
       Label           : Gtk_Label;
       Frame           : Gtk_Frame;
       Button_S        : Gtk_Button;
       General_Error   : exception;

       package Handlers is new Gtk.Handlers.Callback (Gtk_Widget_Record);
       package Return_Handlers is
          new Gtk.Handlers.Return_Callback (Gtk_Widget_Record, Boolean);

       function Delete_Event (Widget : access Gtk_Widget_Record'Class)
          return Boolean is
       begin
          return False;
       end Delete_Event;

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

       procedure Clicked (Widget : access Gtk_Widget_Record'Class) is
       begin

          raise General_Error;
        exception
            when General_Error =>
              null;

       end Clicked;


    begin
       Gtk.Main.Init;
       Gtk.Window.Gtk_New (Window);
       Set_Default_Size (Window, 200, 200);
       Gtk.Window.Set_Title (Window, "GUI_Test_4");
       Gtk_New (Frame);
       Add (Window, Frame);
       Gtk_New (Button_S, "Try");
       Add (Frame, Button_S);

       Return_Handlers.Connect
       (  Window,
          "delete_event",
          Return_Handlers.To_Marshaller (Delete_Event'Access)
       );
       Handlers.Connect
       (  Window,
          "destroy",
          Handlers.To_Marshaller (Destroy'Access)
       );
       Handlers.Connect
       (  Button_S,
          "clicked",
          Handlers.To_Marshaller (Clicked'Access)
       );

       Show_All (Window);
       Show (Window);

       Gtk.Main.Main;

    end gui_test_4;

按下按钮时,会引发异常,但应在同一过程中对其进行管理,但不是这样,而是整个程序崩溃。

知道如何解决这个问题吗?

谢谢

4

1 回答 1

2

Looks like a job for the debugger to me.

In the comments it was mentioned that others are able to successfully run and build this same code. That could mean that your version of GTKAda has issues. It could instead mean that there's a real bug in there, but how/if it expresses depends on what garbage values happened to be loaded into what memory areas when the program starts up.

You might start off by making sure you have the latest version of GTKAda. But after that, fire up the debugger and try to see where its crashing. Note that in Ada programs often crashes happen during package elaboration before the first line of code in your main even gets called. If you are using Gnat you can step through the elaboration process in GDB as well though. With other compilers, you may have to find some elaboration code to try to put breakpoints into to catch it early enough.

于 2012-09-11T18:39:52.623 回答