Quantcast
Channel: Planet Object Pascal
Viewing all articles
Browse latest Browse all 1725

twm’s blog: Segmentation fault on startup in Delphi XE6 Firemonkey application for Android

$
0
0

After I attended the Delphi Power Workshop on mobile development with Delphi XE6 in Essen last week, the mobile development virus has taken hold of me. So I tried successfully to compile the demo apps for both, my Nexus 7 tablet and my Samsung Galaxy Note (GT-N7000) smartphone. That these worked out of the box got me hooked even more.

So, now I am writing my first useful App which is going to be a simple random number generator emulating the various dices used in games (In German dice is “Würfel” and there are several standard ones called W4, W6 (that’s the most widely used one), W8, W10, W12 and W20. My App is going to support these and in addition a custom one.

But back to the topic. I created a new “Firemonkey mobile Application” with a simple form, added a few controls and events and tried to run it on my smartphone. It immediately crashed with a segmentation fault in TFormBorder.GetSupported (unit FMX.Forms). Segmentation fault is the Android (Linux) equivalent of an Access Violation on Windows, most likely caused by referencing a NIL pointer. Being new to Android and Firemonkey development, I was expecting some very simple but hard to trace cause for this, like forgetting to call some initialization function I didn’t know about.

First thing I did was typing the error message and the method name into Google, but nothing turned up. Apparently I was the first one who had encountered that problem and talked about it.

So next I put a breakpoint into the method and checked the variables. As expected, there was a NIL pointer: Self was NIL. I traced back up the call stack and found that apparently the form’s ResizeHandle method was called before the form was properly instantiated. Then it dawned to me. I had made one of the most basic mistake in Delphi development: I had forgotten to call inherited Create in the form’s constructor.

So, even an old hand (or old fart, if you prefer that) in Delphi development can make basic mistakes. Also, what was wrong in Delph 1 in 1995 is still wrong in Delphi XE6 in 2014.

After I fixed this problem, everything works as expected.


Viewing all articles
Browse latest Browse all 1725

Trending Articles