Recent

Author Topic: Why is an exe not running when Lazarus IDE is not used ?  (Read 5423 times)

WimVan

  • Jr. Member
  • **
  • Posts: 76
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #15 on: December 13, 2018, 08:12:28 pm »
@Josh
I did the test.  Nothing is resolved.  While compiling a cmd-box opens and I see a quick run of messages ...  to quick to follow. cmd-box closes automatically and popup of application and closing immediately.  No error-message seen.

@wp
I'll try it, but whom procedures must I change by inserting the writeln ... ?
procedures of the application, or even procedures called in existent units ?
If the last one, how can obtain a list of all procedures whom are used ?

When I trace step by step while compiling I get out in LAZutf8.pas at line 3451, erro-message: External SIGILL

wp

  • Hero Member
  • *****
  • Posts: 6234
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #16 on: December 13, 2018, 08:31:08 pm »
Ah, I forgot that you can step through the code with the debugger. Then the WriteLn's can be avoided.

When the debugger stops with the error in LazUTF8 you should look at the stack-trace: View > Debug windows > Call stack. It shows the crashing line at the top, and, going down, the code lines which were called by the preceding line. Look at the source code at or before these lines and try to find if there is something strange. The error probably means that one of the PChar or PWideChar arguments of the Convert... function points to unassigned memory.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

WimVan

  • Jr. Member
  • **
  • Posts: 76
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #17 on: December 13, 2018, 09:43:27 pm »
Remark: I did that step to step-debugging already.

I let de debugger compile till the formcreate (*************-mark) 

Code: Pascal  [Select]
  1. ********************** procedure TMASTERform.FormCreate(Sender: TObject);
  2. var
  3.   cFile, cappl : string;
  4.   ntmp : integer;
  5. begin
  6. ##############  cappl := ExtractFileName( Application.ExeName);
  7.   ntmp  := length(cappl)  ;
  8.   cappl := copy( cappl, 1, ntmp - 4);
  9.   cFile := ExtractFilePath( Application.ExeName) + cappl + '.def';
  10.  

The debugger stops at (second marker###################) and from there I step throw the code ...

Code: Pascal  [Select]
  1. program collectie_beheer;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Interfaces, // this includes the LCL widgetset
  10.   Forms, collectie_beheer_1, collection_image_viewer
  11.   { you can add units after this };
  12.  
  13. {$R *.res}
  14.  
  15. begin
  16.   RequireDerivedFormResource:=True;
  17. ***********  Application.Initialize;
  18.   Application.CreateForm(TMASTERform, MASTERform);
  19.   Application.CreateForm(TVIEWERform, VIEWERform);
  20.   Application.Run;
  21. end.
  22.  

Then I step further ...
Application.inc is already open where the last procedures compiled successfully:
Code: Pascal  [Select]
  1. {------------------------------------------------------------------------------
  2.   Method: TApplication.GetTitle
  3.   Returns: title of application
  4.  ------------------------------------------------------------------------------}
  5. function TApplication.GetTitle: string;
  6. begin
  7.   Result := inherited Title;
  8.   if Result = '' then
  9.     Result := ExtractFileNameOnly(GetExeName);
  10. end;

Then LazUTF8.pas is used and the debugger jumps to line 3734 (marker)
I can step further where at the second  line (indicated with ######### the debugger stops with the error : External SIGILL
Hitting OK gives me the line 3451

Code: Pascal  [Select]
  1. {------------------------------------------------------------------------------
  2.   Name:    UTF8ToUTF16
  3.   Params:  S - Source UTF-8 string
  4.   Returns: UTF-16 encoded string
  5.  
  6.   Converts the specified UTF-8 encoded string to UTF-16 encoded (system endian)
  7.   Avoid copying the result string since on windows a widestring requires a full
  8.   copy
  9.  ------------------------------------------------------------------------------}
  10. *********** function UTF8ToUTF16(const S: AnsiString): UnicodeString;
  11. begin
  12.   Result:=UTF8ToUTF16(PChar(S),length(S));
  13. end;
  14.  
  15. function UTF8ToUTF16(const P: PChar; ByteCnt: SizeUInt): UnicodeString;
  16. var
  17.   L: SizeUInt;
  18. begin
  19.   if ByteCnt=0 then
  20.     exit('');
  21.   SetLength(Result, ByteCnt);
  22.   // wide chars of UTF-16 <= bytes of UTF-8 string
  23. #############  if ConvertUTF8ToUTF16(PWideChar(Result), Length(Result) + 1, P, ByteCnt,
  24.     [toInvalidCharToSymbol], L) = trNoError
  25.   then SetLength(Result, L - 1)
  26.   else Result := '';
  27. end;
  28.  

I copied the function in LAZUTF8.pas where the debuggers finally stops and hitting F7 again I got the message execution broken ... wihtout an error-message.
Line 3451 is marked in red !

Code: Pascal  [Select]
  1.   function InvalidCharError(Count: SizeUInt): Boolean; inline;
  2.   begin
  3.     if not (toInvalidCharError in Options) then
  4.     begin
  5.       if toInvalidCharToSymbol in Options then
  6.       begin
  7.         Dest[DestI] := System.WideChar('?');
  8.         Inc(DestI);
  9.       end;
  10.  
  11.       Dec(SrcI, Count);
  12.  
  13.       // skip trailing UTF-8 char bytes
  14.       while (Count > 0) do
  15.       begin
  16.         if (Byte(Src[SrcI]) and %11000000) <> %10000000 then Break;
  17.         Inc(SrcI);
  18.         Dec(Count);
  19.       end;
  20.  
  21.       Result := False;
  22.     end
  23.     else
  24.       if toInvalidCharError in Options then
  25.       begin
  26.         ConvertUTF8ToUTF16 := trUnfinishedChar;
  27.         Result := True;
  28.       end;
  29.   end;
  30.  
  31. **************  begin
  32.   ActualWideCharCount := 0;
  33.  
  34.   if not Assigned(Src) then
  35.   begin
  36.     Result := trNullSrc;
  37.     Exit;
  38.   end;
  39.  
  40.   if not Assigned(Dest) then
  41.   begin
  42.     Result := trNullDest;
  43.     Exit;
  44.   end;
  45.   SrcI := 0;
  46.   DestI := 0;
  47.  

I hope this brings us somewhat further.
« Last Edit: December 13, 2018, 09:49:36 pm by WimVan »

rvk

  • Hero Member
  • *****
  • Posts: 3836
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #18 on: December 13, 2018, 10:37:01 pm »
Still think the problem is not in code.
Is the location of the database on the same.path with both pc and laptop?
If not, how are you filling those values (for databasepath/name)?
Do you have any connection.active set to true in design time or is active false and you set it in run-time?

Ps. Why do you, as a developer, don't have access to the antivirus-settings?

WimVan

  • Jr. Member
  • **
  • Posts: 76
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #19 on: December 13, 2018, 11:06:32 pm »
database is installed and running on an external HD.  Driveletter F:
On the laptop 1, and Laptop 2 and the PC, taht external disk is knwon as the F-drive.
Databse Mariadb is started up on the F:-disk
So, whatever I use, the database is the same, paths are the same .. used libmysql.dll is the same.

Why I have no priviledge to stop the anti-virus or modify it behaviour ?  Simple, that laptop resides in the network of the company where I work.  It is a request from audit, security that nobody has full admin-rights.  Only local and the several parameters of the laptop can't be change.

The second laptop, I own full admin rights. When stopping Aanti-virus for some minutes, the application still not run !

wp

  • Hero Member
  • *****
  • Posts: 6234
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #20 on: December 14, 2018, 10:13:03 am »
Remark: I did that step to step-debugging already.
...
Sorry I cannot follow these steps... Do I understand correctly that the crash happens in Application.CreateForm(TMasterForm, MasterForm) somewhere related to Application.GetTitle? But AFAICS this does not require the UTF8-to-UTF16 conversion... And what did you do that you can step into LCL units? Normally this is not possible.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

rvk

  • Hero Member
  • *****
  • Posts: 3836
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #21 on: December 14, 2018, 10:21:52 am »
You said all this happened after adding the second form to the program (I guess TVIEWERform).

What happens if you remove it?
What is included in the uses of TVIEWERform what is missing in TMASTERform?

You can look at the code all you want but I don't think you'll find the solution there (unless it is to debug where the crash happens). The .exe from the other machine also won't run on the laptop (while it runs on the PC just fine). To me, that says it must be an environment issue.

Also, the fact you see a blank window just before the crash (TMasterform?) says the crash happens after FormCreate and even after FormShow. Try setting a Showmessage at the end of FormCreate and one in FormShow and see if that's true.

WimVan

  • Jr. Member
  • **
  • Posts: 76
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #22 on: December 14, 2018, 12:56:37 pm »
I'm out of resources ...
  • I tried installing the 32/64 Lazarus-verision.  Installed the 32bits libmysql.dll. I can connect in development. But when I tried to compile I see a popup of the applications with  a great fart of the form and then it closes immediately.  A message is returned that the appilication-execution is broken. No error on codes, libmysql.dll
  • I tried installing the 64 Lazarus-verision.  Installed the 64bits libmysql.dll. I can connect in development. But when I tried to compile I see a popup of the applications with  a great fart of the form and then it closes immediately.  A message is returned that the appilication-execution is broken. No error on codes, libmysql.dll
  • When once this strange behavour occurs it becomes very difficult to find out when the application can be compiled and RUN.
      I already tried this some times and in some cases it is sufficient to remove the second form, on other times I came to the point where only a pagecontrol, tabsheet and some labels and edit-components are left over .

32bit Laptop164bit Laptop132bit Laptop264bit Laptop32bit PC64bit PC
Run on developmentNoNoNoNoYesYes


Laptop1Laptop2PC
Run as exeNoNoYes
Run as exe created on Laptop1 32bitNoNoYes
Run as exe created on Laptop1 64bitNoNoYes
Run as exe created on Laptop2 32bitNoNoYes
Run as exe created on Laptop2 64bitNoNoYes
Run as exe created on PC 32bitNoNoYes
Run as exe created on PC 64bitNoNoYes

That the environment has an impact ? Laptop 2 and PC have the same windowsbuild (except of course of drivers, ... but Win10 was installed the same way and it owns the same updates.

« Last Edit: December 14, 2018, 01:04:38 pm by WimVan »

rvk

  • Hero Member
  • *****
  • Posts: 3836
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #23 on: December 14, 2018, 01:03:17 pm »
Did you try any of the things I mentioned below?

i.e. removing TVIEWERForm again and/or putting Showmessage at several places.

I still think some other program just kills the program when it started.
Do you have some entries in the Windows Event Viewer (in Applications)?


You said all this happened after adding the second form to the program (I guess TVIEWERform).

What happens if you remove it?
What is included in the uses of TVIEWERform what is missing in TMASTERform?

You can look at the code all you want but I don't think you'll find the solution there (unless it is to debug where the crash happens). The .exe from the other machine also won't run on the laptop (while it runs on the PC just fine). To me, that says it must be an environment issue.

Also, the fact you see a blank window just before the crash (TMasterform?) says the crash happens after FormCreate and even after FormShow. Try setting a Showmessage at the end of FormCreate and one in FormShow and see if that's true.

af0815

  • Sr. Member
  • ****
  • Posts: 348
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #24 on: December 14, 2018, 01:05:00 pm »
a) What kind of exe have you compiled Win32 or Win64 ? Have you used the correct dlls and are this dlls available for the programm. Maybe in the same dir like the executable.
b)Have you tried to start the executable from a commandline ? Normally you see more information on the commandline. What is the message here ?
c) Not the windowsbuild have the great impact, more impact have the installed libraries.

 
regards
Andreas

BrunoK

  • Full Member
  • ***
  • Posts: 181
  • Retired programmer
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #25 on: December 14, 2018, 01:55:58 pm »
It smells a too small buffer for conversion.

Try to change line  (3786 ?) in LazUTf8
SetLength(Result, ByteCnt);
to
SetLength(Result, ByteCnt+8); // +8 or maybe a bigger value

if it works you had a buffer overrun due to a bug (?), maybe due to the type of Utf8 char that could not be correctly be translated to UCS-2 (UTF-16).

If that's the case you have to be very careful about what caused the ConvertUTF8ToUTF16 to put out an Unfinished character.
Lazarus trunk r. 59978/03.01.2019 (+/- patches regarding enabled, TScrollBar, TCursorImage). FPC 3.0.4 32 bits. (+heaptrc with leaked ClassName+Revisited TList) , Windows 10 Pro x64 (v. 1903)

rvk

  • Hero Member
  • *****
  • Posts: 3836
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #26 on: December 14, 2018, 01:59:47 pm »
It smells a too small buffer for conversion.
I wouldn't trust the debugger (note that we are talking about gdb here) to pinpoint the exact crash location in this case.

When another program just kills the process, the gdb debugger will go completely nuts.

Since the same .exe (both the one compiled on laptop and PC) runs just fine on PC, I can't imagine it is something in code.

WimVan

  • Jr. Member
  • **
  • Posts: 76
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #27 on: December 14, 2018, 02:36:16 pm »
Removed form2 then asked a clean build ...  No result. Same popup andclosing directly
remove/add form2 and a clean build ... Nothing changes

I have a form1create-procedure;
putting a showmessage at the beginning and at the end let see both messages while compiling ...
popup and closure ..

For the rest, I have now & form with some components and I have about 15 procdures that are fired when the application got focus and when, then you request for something.

Stupied question (more and more I will ask such). Can there be something about the path ?

I also changed the value in LAZUTF8.pas as mentioned ... No impact at all...
If someone wants the resources ... just ask for them. The DB I can deliver as  a ZIpped SQL

 :( %) :'(

rvk

  • Hero Member
  • *****
  • Posts: 3836
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #28 on: December 14, 2018, 02:44:03 pm »
You could still try something else... to determine it is something from the outside...

*) Put Dialogs in the uses of your project.lpr and put a Showmessage('a'); above Application.Initialize;
If the program still quits it is really something from the outside.
Showmessage is run before Application.Initialize but a second later (before you can press OK) some other program realizes you started this program and kills it.

*) What happens if you just create an empty project? Does that still work? (Just one form with a button and nothing else)

(Did you already look in the Event Viewer of Windows?)
« Last Edit: December 14, 2018, 02:46:38 pm by rvk »

WimVan

  • Jr. Member
  • **
  • Posts: 76
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #29 on: December 14, 2018, 02:53:19 pm »
1) I inserted your suggestion.  While compiling I got the message. Hitting ok, form pops up and closes immediately?
2) I can start a new project ...  as long this strange behaviour does not appear I can edit, modify, build, run that application.  So do I have several tools I made that are running.
The development for these tools is done on Laptop1 and when I'm at home on the PC.  The sources resides on an external portable HD.  Lazarus is installed the same way and on the Laptop or PC.
But, once the error appears (when I edited the application on the PC and then moves to the Laptop) is it done for infinity.
Problem is, it does not always happens and I can't tell when it happens because I edit several items and not just one line

program collectie_beheer;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Interfaces, // this includes the LCL widgetset
  Forms, collectie_beheer_1, Dialogs;

{$R *.res}

begin
  RequireDerivedFormResource:=True;
  Application.Initialize;
  Application.CreateForm(TMASTERform, MASTERform);
  Showmessage('a');
  Application.Run;
end.


When I put the message after creation of the form, I got that message too.  So, problem somewhere when running

Note. PC and Laptop & owns a Intel-rpocessor, Laptopé is an AMD



It rends me sick ...
« Last Edit: December 14, 2018, 02:58:03 pm by WimVan »