* * *

Author Topic: Project * raised exception class 'External: ?'. in Windows  (Read 546 times)

Eugene Loza

  • Hero Member
  • *****
  • Posts: 506
    • My "almost daily" development blog
Project * raised exception class 'External: ?'. in Windows
« on: September 14, 2017, 05:52:37 am »
Project * raised exception class 'External: ?'.
What kind of beast is that and where should I start looking?

Debian Jessie 64 bit, Lazarus 1.8.0RC3, FPC3.0.3 64 bit - everything works flawlessly.
Windows 7 64 bit, Lazarus 1.6.4, FPC 3.0.2 32 bit - 'External: ?'
Yes, project depends on some dlls, and they are 32 bit.

(Yes, I rarely use Windows, and that version is a few weeks older than last confirmed-stable one, there were a lot of changes in the code sicne)
If I disable some (very trivial) classes creation, everything works fine. The only suspect may be a custom timer processing (it's implementation is Windows-related), however I tested it and it worked with no issues before...
Maybe last upgrade of ZoneAlarm Free antivirus+firewall stands in the way?

Anyway, what does 'External: ?' mean?
« Last Edit: September 14, 2017, 05:57:08 am by Eugene Loza »
Lazarus 1.9 + FPC 3.1.1 Debian Jessie 64 bit.

My Free and Open Source games in Lazarus/FreePascal/CastleGameEngine:
https://decoherence.itch.io/
(and some ancient games in Turbo Pascal too)
Sources are here: https://github.com/eugeneloza?tab=repositories

howardpc

  • Hero Member
  • *****
  • Posts: 2393
Re: Project * raised exception class 'External: ?'. in Windows
« Reply #1 on: September 14, 2017, 09:37:28 am »
If you are running under the debugger, possibly it comes from
.../lazarus/components/fpdebug/fpdbgwinclasses.pas
at line 615
Code: Pascal  [Select]
  1. ExceptionClass:='External: '+ExceptionClass;

If so, you could put a breakpoint somewhere there and get a stack trace to see what (dll call?) immediately precedes this exception.

Eugene Loza

  • Hero Member
  • *****
  • Posts: 506
    • My "almost daily" development blog
Re: Project * raised exception class 'External: ?'. in Windows
« Reply #2 on: September 14, 2017, 06:09:21 pm »
@howardpc, thanks!

By trial-and-error I've localized the error. That stuff happened when I switched off the Thread working in a Thread and just ran it directly by Thread.Execute. However, I forgot that I have Thread.FreeOnTerminate = true. On one hand this error is relatively obvious :) On the other hand... some more informative error report would have been very welcome :) E.g. I couldn't have guessed that  Thread.FreeOnTerminate = true would free the thread class even after directly calling Execute. Thou, my fault, as usually  :-[
Even more strange is why the same code works perfectly under Linux then?
Code: Pascal  [Select]
  1. program Project1;
  2. uses Classes, SysUtils;
  3.  
  4. type TMyThread = class(TThread)
  5.   protected
  6.     procedure Execute; override;
  7.   end;
  8.  
  9. procedure TMyThread.Execute;
  10. begin
  11.   WriteLn('ho-ho-ho');
  12. end;
  13.  
  14. var MyThread: TMyThread;
  15.  
  16. begin
  17.   MyThread := TMyThread.Create(true);
  18.   MyThread.FreeOnTerminate := true; //<---------- THERE IT GOES
  19.   MyThread.Execute;
  20.   FreeAndNil(MyThread); //<---------------- And here we get "EXTERNAL: ?" exception
  21. end.
  22.  
« Last Edit: September 14, 2017, 06:14:20 pm by Eugene Loza »
Lazarus 1.9 + FPC 3.1.1 Debian Jessie 64 bit.

My Free and Open Source games in Lazarus/FreePascal/CastleGameEngine:
https://decoherence.itch.io/
(and some ancient games in Turbo Pascal too)
Sources are here: https://github.com/eugeneloza?tab=repositories

howardpc

  • Hero Member
  • *****
  • Posts: 2393
Re: Project * raised exception class 'External: ?'. in Windows
« Reply #3 on: September 14, 2017, 07:32:30 pm »
Linux always has a terminal that Writeln can use.
Windows only if you specifically provide for it with {$AppType console} or in some other way.

Eugene Loza

  • Hero Member
  • *****
  • Posts: 506
    • My "almost daily" development blog
Re: Project * raised exception class 'External: ?'. in Windows
« Reply #4 on: September 14, 2017, 07:51:36 pm »
Well, that was just a minimalistic example. Althou, I tested it and it worked with console ok under Windows. So the problem is not there.

The problem was that the Thread was "freed" twice.
Once due to FreeOnTerminate=true;
Thread.Execute -> Thread freed and Thread variable no longer pointing at a valid address.
and Second time by FreeAndNil(@some_already_invalid_pointer);
Lazarus 1.9 + FPC 3.1.1 Debian Jessie 64 bit.

My Free and Open Source games in Lazarus/FreePascal/CastleGameEngine:
https://decoherence.itch.io/
(and some ancient games in Turbo Pascal too)
Sources are here: https://github.com/eugeneloza?tab=repositories

Eugene Loza

  • Hero Member
  • *****
  • Posts: 506
    • My "almost daily" development blog
Re: Project * raised exception class 'External: ?'. in Windows
« Reply #5 on: September 14, 2017, 07:55:38 pm »
The more the merrier. Linux REQUIRES to free the Thread manually. Otherwise it gives a memory leak.
Quote
Heap dump by heaptrc unit
27 memory blocks allocated : 1990/1992
25 memory blocks freed     : 1790/1792
2 unfreed memory blocks : 200
True heap size : 393216
True free heap : 392704
Should be : 392760
Call trace for block $00007FFFF7FE66C0 size 96
  $00000000004390DA
Call trace for block $00007FFFF7FE65C0 size 104
and while -gl and -gh are active, there is no reference to specific lines of code...

I.e. threads behave significantly DIFFERENT in Windows and Linux.

Windows: FreeOnTerminate frees thread after Thread.Execute;
Linux: FreeOnTerminate doesn't free thread after Thread.Execute;
« Last Edit: September 14, 2017, 07:57:33 pm by Eugene Loza »
Lazarus 1.9 + FPC 3.1.1 Debian Jessie 64 bit.

My Free and Open Source games in Lazarus/FreePascal/CastleGameEngine:
https://decoherence.itch.io/
(and some ancient games in Turbo Pascal too)
Sources are here: https://github.com/eugeneloza?tab=repositories

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus