Recent

Author Topic: [SOLVED]till now, i have doubt on win10 of console application  (Read 2217 times)

powerpcer

  • Jr. Member
  • **
  • Posts: 53
when i make a console application on a win10, and run it inside CMD.exe
on 2 PC, 1 with Anti-Virus  trend micro, other no Anti-Virus.
they both has same problem, that's when i build my program, and type its name to run.
most of time, it will run a part of code and then terminated on first run,
when i run it more times, then it will run correctly.
and i had put try catch to get exception message, but no exception generated.
so it looks just run and terminated in half.
but if i run in on LAZARUS IDE, it will always run correctly.....
what a strange things.
« Last Edit: May 29, 2021, 03:31:14 am by powerpcer »

powerpcer

  • Jr. Member
  • **
  • Posts: 53
Re: till now, i have doubt on win10 of console application
« Reply #1 on: May 28, 2021, 01:51:08 pm »
for example. second time is terminated unexpected.

Code: Pascal  [Select][+][-]
  1. D:\APP\FPC component\WLF>WLF.exe -ser ofac "KORYO BONK"
  2. WLF start..
  3. WLF params ready
  4. WLF SEARCH
  5. LoadIndex:0
  6. Search:1
  7. TimerIdleTick: finished: 30ms
  8.  
  9. D:\APP\FPC component\WLF>WLF.exe -ser ofac "KORYO BONK"
  10. WLF start..
  11. WLF params ready
  12. WLF SEARCH
  13.  
  14. D:\APP\FPC component\WLF>
  15.  

and look at my code below, if there is exception, i should catch, but no exception was catch, so strange!!

Code: Pascal  [Select][+][-]
  1. var
  2.   etl:TETLName;
  3.   i,j:integer;
  4.   NTickInitial,NTickShowEnd: QWord;
  5.   p1:Puint32;
  6.   p:P2duint32;
  7.   params:array of string;
  8.   fname:string;
  9.   casevalue:Tparamvalue;
  10.   istack:TIStack;
  11.  
  12. {$R *.res}
  13.  
  14. begin
  15.   {istack:=TIStack.create(8);
  16.   for i:=1 to 8 do
  17.    istack.push(i);
  18.   istack.pop(j);
  19.   istack.pop(j);
  20.   for i:=9 to 15 do
  21.    istack.push(i);
  22.   while (istack.pop(j)) do
  23.   begin
  24.        writeln(stdout,j);
  25.   end;
  26.   exit;}
  27.   writeln(stdout,'WLF start..');
  28.   NTickInitial:= GetTickCount64;
  29.   fname:='ofac.txt';
  30.   casevalue:=DOETL;
  31.   if paramCount()>1 then
  32.   begin
  33.      setlength(params,paramCount());
  34.      for i := 1 to paramCount() do
  35.      begin
  36.           params[i-1]:= paramStr(i);
  37.      end;
  38.      if params[0]='-etl' then
  39.      begin
  40.         fname:=params[1];
  41.         casevalue:=DOETL;
  42.      end
  43.      else
  44.      if params[0]='-ser' then
  45.      begin
  46.         fname:=params[1];
  47.         casevalue:=SEARCH;
  48.      end
  49.      else
  50.      if params[0]='-pub' then
  51.      begin
  52.         fname:=params[1];
  53.         casevalue:=PUBLISH;
  54.      end
  55.      else
  56.      if params[0]='-peq' then
  57.      begin
  58.         fname:=params[1];
  59.         casevalue:=EQLIST;
  60.      end
  61.      else
  62.      if params[0]='-pew' then
  63.      begin
  64.         fname:=params[1];
  65.         casevalue:=EQWORD;
  66.      end
  67.      else
  68.      if params[0]='-pst' then
  69.      begin
  70.         fname:=params[1];
  71.         casevalue:=SETTINGLIST;
  72.      end
  73.      else
  74.      if params[0]='-dmp' then
  75.      begin
  76.         fname:=params[1];
  77.         casevalue:=DUMPINDEX;
  78.      end;
  79.      if params[0]='-brf' then
  80.      begin
  81.         fname:=params[1];
  82.         casevalue:=BRUTEFORCE;
  83.      end;
  84.   end;
  85.   writeln(stdout,'WLF params ready');
  86.   etl:=TETLName.create(fname);
  87.   try
  88.   case casevalue of
  89.        DOETL:
  90.          begin
  91.               writeln(stdout,'WLF DOETL');
  92.               i:=etl.startETL();
  93.               writeln(stdout,'startETL:'+inttostr(i));
  94.               i:=etl.GenerateIndex();
  95.               writeln(stdout,'GenerateIndex:'+inttostr(i));
  96.          end;
  97.        SEARCH:
  98.          begin
  99.               writeln(stdout,'WLF SEARCH');
  100.               i:=etl.LoadIndex(fname);
  101.               writeln(stdout,'LoadIndex:'+inttostr(i));
  102.               i:=etl.Search(params[2],3);
  103.               writeln(stdout,'Search:'+inttostr(i));
  104.          end;
  105.        DUMPINDEX:
  106.          begin
  107.               writeln(stdout,'WLF DUMPINDEX');
  108.               i:=etl.DumpIndex(fname);
  109.               writeln(stdout,'DumpIndex:'+inttostr(i));
  110.          end;
  111.        BRUTEFORCE:
  112.          begin
  113.              writeln(stdout,'WLF BRUTEFORCE');
  114.              i:=etl.LoadIndex(fname);
  115.              writeln(stdout,'LoadIndex:'+inttostr(i));
  116.              i:=etl.bruteforce(params[2],3);
  117.              writeln(stdout,'bruteforce:'+inttostr(i));
  118.          end;
  119.   end;
  120.   except
  121.     on E: Exception do
  122.     begin
  123.     writeln(stdout,'casevalue handling error occurred. Details: ', E.ClassName, '/', E.Message);
  124.     DumpExceptionCallStack(E);
  125.     end;
  126.   end;
  127.   etl.Free;
  128.   NTickShowEnd:= GetTickCount64;
  129.   writeln(StdOut,Format('TimerIdleTick: finished: %dms', [(NTickShowEnd-NTickInitial) div 10 * 10]));
  130.  
« Last Edit: May 28, 2021, 02:21:52 pm by powerpcer »

ASerge

  • Hero Member
  • *****
  • Posts: 1839
Re: till now, i have doubt on win10 of console application
« Reply #2 on: May 28, 2021, 08:00:32 pm »
These kinds of errors (unstable behavior) usually mean that an area of memory is being overwritten somewhere. Possible reasons: use of already freed memory, incorrect pointer dereferencing, etc.
Obviously, the problem lies in this part of the code.
Code: Pascal  [Select][+][-]
  1.        SEARCH:
  2.          begin
  3.               writeln(stdout,'WLF SEARCH');
  4.               i:=etl.LoadIndex(fname);
  5.               writeln(stdout,'LoadIndex:'+inttostr(i));
  6.               i:=etl.Search(params[2],3);
  7.               writeln(stdout,'Search:'+inttostr(i));
  8.          end;
Since the snippet you attached doesn't reveal it, then either look for the error yourself, or show what these methods do and how.

engkin

  • Hero Member
  • *****
  • Posts: 2924
Re: till now, i have doubt on win10 of console application
« Reply #3 on: May 28, 2021, 08:39:41 pm »
And for this instance, based on your screenshot, it *most likely* happened inside LoadIndex:
Code: Pascal  [Select][+][-]
  1.            SEARCH:
  2.              begin
  3.                   writeln(stdout,'WLF SEARCH');
  4.                   i:=etl.LoadIndex(fname);
  5.                   writeln(stdout,'LoadIndex:'+inttostr(i));
  6.                   i:=etl.Search(params[2],3);
  7.                   writeln(stdout,'Search:'+inttostr(i));
  8.              end;


powerpcer

  • Jr. Member
  • **
  • Posts: 53
Re: till now, i have doubt on win10 of console application
« Reply #4 on: May 29, 2021, 03:30:52 am »
These kinds of errors (unstable behavior) usually mean that an area of memory is being overwritten somewhere. Possible reasons: use of already freed memory, incorrect pointer dereferencing, etc.
Obviously, the problem lies in this part of the code.
Code: Pascal  [Select][+][-]
  1.        SEARCH:
  2.          begin
  3.               writeln(stdout,'WLF SEARCH');
  4.               i:=etl.LoadIndex(fname);
  5.               writeln(stdout,'LoadIndex:'+inttostr(i));
  6.               i:=etl.Search(params[2],3);
  7.               writeln(stdout,'Search:'+inttostr(i));
  8.          end;
Since the snippet you attached doesn't reveal it, then either look for the error yourself, or show what these methods do and how.
thanks, finally i found that FileRead(afile,buffer,4096);
the "buffer" is pbyte, it will show unstable behavior, if change to array, it looks good.

 

TinyPortal © 2005-2018