Class segmentation fault (11)

Oussama Al Rifai picture Oussama Al Rifai · Nov 9, 2013 · Viewed 9k times · Source

Please follow the steps below:

  1. Create New Firemonkey Moblie Application
  2. Add TGeustureManager component to the Form
  3. Add 2 TButton components to the Form

    • Button1.Text: "Button1: Do something..."
    • Button2.Text: "Button2: Exit Application..."

    The application should appear like this

  4. Double click on Button2 Component and write the following code for OnClick Event:

    procedure TForm1.Button2Click(Sender: TObject);
    begin
      if MessageDlg('Are you sure you want to Exit?', TMsgDlgType.mtWarning,
              [TMsgDlgBtn.mbYes, TMsgDlgBtn.mbNo], 0) = mrYes then
        SharedActivity.finish;
    end;
    
  5. Run the application in debug mode.
  6. on the device, click the button 2, then click yes to the popped up message. An exception will appear:

    enter image description here

Why is this exception raised?

I thought it is related to unused TGeustureManager component. but NO it is NOT:

  1. If you open the Location Demo project that comes with Delphi xe5.
  2. Add TButton component to Location Label as shown in the image below: enter image description here
  3. Add the same code as above to OnClick Event.
  4. Run the application, and click on Button5, you will get the same exception.

Is this a bug should I report? or am I doing something wrong?

Answer

blong picture blong · Nov 13, 2013

Possibly that you are killing the activity that is running, before its execution flow has been exhausted, thereby causing problems. Much like freeing a form in a form method....

What happens if you replace:

SharedActivity.finish

with:

uses
  FMX.Helpers.Android;
...
CallOnUIThread(procedure begin SharedActivity.finish end);

[ Typed from memory, so may need some tweaking ]