Recent

Author Topic: Crashes on release mode on Lazarus only  (Read 1220 times)

YiannisKam

  • Full Member
  • ***
  • Posts: 119
Crashes on release mode on Lazarus only
« on: August 14, 2024, 05:51:32 pm »
The program below compiles and runs fine on debug mode on lazarus but fails to run properly on release mode particularly when trying to get ReadLn(PauseInput'); Why? Is it a bug?
And the weird thing is that when I compile and run from command line it works fine.
The crt unit is there because I'll need it later on for the GotoXY function..
Lazarus and compiler, both trunk.

Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   SysUtils, crt;
  7.  
  8. var
  9.   TotalReps, BeepInterval, PauseDuration: Integer;
  10.   PauseInput: String;
  11.  
  12.  
  13. // Main program starts here
  14. begin
  15.   // Get the user input
  16.   Write('Enter Total Reps: ');
  17.   ReadLn(TotalReps);
  18.  
  19.   Write('Enter Pause Duration(or ENTER for default = 6): ');
  20.   ReadLn(PauseInput);
  21.  
  22.   if not TryStrToInt(PauseInput, PauseDuration) then
  23.     PauseDuration := 6;
  24.  
  25.   if PauseDuration < 6 then
  26.     PauseDuration := 6;
  27.  
  28.   Write('Enter Interval: ');
  29.   ReadLn(BeepInterval);
  30.  
  31.   ReadLn;
  32. end.
  33.  
Windows 10 - 64bit
Lazarus version: 3.99
FPC       version: 3.3.1

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10553
  • Debugger - SynEdit - and more
    • wiki
Re: Crashes on release mode on Lazarus only
« Reply #1 on: August 14, 2024, 06:01:03 pm »
"Release mode" probably also means that "F9" in the IDE uses "run without debugger".  (not sure depends on exact Lazarus version).


I assume this might be Linux?

Then, when you run in the debugger or from a terminal (outside the IDE) there are StdIn/Out/Err set up (the debugger sets them to the IDE "debug > console output" which also acts as input).

But if you run without debugger, then there is no StdIn (nor StdOut/Err). And then you get an error.

YiannisKam

  • Full Member
  • ***
  • Posts: 119
Re: Crashes on release mode on Lazarus only
« Reply #2 on: August 14, 2024, 06:09:24 pm »
Sorry for forgetting to mention, I'm on Windows 10 64 bit. I set my project compiler options on release mode and I press (Run)F9, (not Run without debugging Shift-Ctrl-F9).
« Last Edit: August 14, 2024, 06:12:14 pm by YiannisKam »
Windows 10 - 64bit
Lazarus version: 3.99
FPC       version: 3.3.1

af0815

  • Hero Member
  • *****
  • Posts: 1379
Re: Crashes on release mode on Lazarus only
« Reply #3 on: August 14, 2024, 06:39:46 pm »
I think you start without a console. And on windows there is no aotomatic created console, so as Martin_fr say - it crash. You can remove the check from win32GUI app in the Project options (Compiler Options -> Config and Target) so a console will automatic created (on windows).
regards
Andreas

YiannisKam

  • Full Member
  • ***
  • Posts: 119
Re: Crashes on release mode on Lazarus only
« Reply #4 on: August 14, 2024, 06:50:39 pm »
No, it's not a gui app, it's command line program. Another weird thing that I've noticed is if I remove completely the crt unit and try the release mode on lazarus it works fine. That's really weird and doesn't make any sense.
Windows 10 - 64bit
Lazarus version: 3.99
FPC       version: 3.3.1

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10553
  • Debugger - SynEdit - and more
    • wiki
Re: Crashes on release mode on Lazarus only
« Reply #5 on: August 14, 2024, 07:46:41 pm »
Sorry for forgetting to mention, I'm on Windows 10 64 bit. I set my project compiler options on release mode and I press (Run)F9, (not Run without debugging Shift-Ctrl-F9).

Well, if you are on windows, did you compile as console app? Does a console window opens when your app is run?


On Windows indeed StdIn/StdOut do not depend on the run with/without debugger. They only depend on the presence of such a console window, that should open up when your app is started.

That said, if you have Lazarus 3.n and the project (or the build modes) are new, then when you have "release mode" F9 is re-mapped to "run without debugger". (But it does not matter for your issue)


--- EDIT: just seen, partly answered in later posts...

YiannisKam

  • Full Member
  • ***
  • Posts: 119
Re: Crashes on release mode on Lazarus only
« Reply #6 on: August 14, 2024, 08:16:13 pm »
Project-New Project-Program and yes when I pressed run, the console window appeared. That's all. I experimented and removed the crt unit and it runs without any problem. But I want the crt unit for the GotoXY function.
Windows 10 - 64bit
Lazarus version: 3.99
FPC       version: 3.3.1

Thaddy

  • Hero Member
  • *****
  • Posts: 16190
  • Censorship about opinions does not belong here.
Re: Crashes on release mode on Lazarus only
« Reply #7 on: August 14, 2024, 08:56:12 pm »
remove crt. Period.
If I smell bad code it usually is bad code and that includes my own code.

YiannisKam

  • Full Member
  • ***
  • Posts: 119
Re: Crashes on release mode on Lazarus only
« Reply #8 on: August 14, 2024, 09:23:40 pm »
Any alternative to GotoXY?
Windows 10 - 64bit
Lazarus version: 3.99
FPC       version: 3.3.1

korba812

  • Sr. Member
  • ****
  • Posts: 442
Re: Crashes on release mode on Lazarus only
« Reply #9 on: August 14, 2024, 09:35:25 pm »
Do you get an error message, an exception, or does the console just disappear with the process of your application?
I have a similar problem with the fpc compiler - while compiling my project under Win 10, the console from time to time simply disappears along with the fpc process without any message.
remove crt. Period.
Why?

YiannisKam

  • Full Member
  • ***
  • Posts: 119
Re: Crashes on release mode on Lazarus only
« Reply #10 on: August 14, 2024, 09:40:13 pm »
I don't get any error. The console just disappears when trying to get input for the PauseInput variable. It disappears as soon as I press the enter key. What is weird is, if you remove the crt unit the program works fine. So I thought it would be nice to post the behavior here incase this is a bug. That all.
Windows 10 - 64bit
Lazarus version: 3.99
FPC       version: 3.3.1

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10553
  • Debugger - SynEdit - and more
    • wiki
Re: Crashes on release mode on Lazarus only
« Reply #11 on: August 14, 2024, 10:07:28 pm »
I just found
Quote
Windows 10 - 64bit
Lazarus version: 3.99
FPC       version: 3.3.1
Unfortunately the forum hides your sig, when the "post reply form" is open, so I failed to see it before.



Have you tried with fpc 3.2.3 ?

I tested with (Win 10)
- Lazarus 3.4 fpc 3.2.2 => not reproduced
- Lazarus 3.99 Fpc 3.2.3 (and the IDE itself having a console win) => not reproduced.

I don't want to rebuild my tools now... So I wont test other combinations.

There could be (unknown) an issue if:
- The IDE is build with fpc 3.3.1
- your app is build with fpc 3.3.1

Further more, it could depend on the very exact compiler settings during compilation -o2 or -o3 -C...  and what not.... And it could also depend on the day on which you last upgraded your 3.3.1

YiannisKam

  • Full Member
  • ***
  • Posts: 119
Re: Crashes on release mode on Lazarus only
« Reply #12 on: August 14, 2024, 10:23:46 pm »
The forum is fine. I've set my signature after creating this topic and my apologies I haven't done that earlier.
I don't have any other compiler version installed. I used fpcupdeluxe if makes an important role to this 'issue' (Build Date: 2024-08-04 11:19)
Windows 10 - 64bit
Lazarus version: 3.99
FPC       version: 3.3.1

cdbc

  • Hero Member
  • *****
  • Posts: 1667
    • http://www.cdbc.dk
Re: Crashes on release mode on Lazarus only
« Reply #13 on: August 14, 2024, 10:45:17 pm »
Hi
Hmmm... Have you tried {$APPTYPE CONSOLE} just below {$mode objfpc}{$H+}
IIRC this is needed on winders, for console apps
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10553
  • Debugger - SynEdit - and more
    • wiki
Re: Crashes on release mode on Lazarus only
« Reply #14 on: August 14, 2024, 10:49:40 pm »
The forum is fine. I've set my signature after creating this topic and my apologies I haven't done that earlier.
I don't have any other compiler version installed. I used fpcupdeluxe if makes an important role to this 'issue' (Build Date: 2024-08-04 11:19)
Press reply, and while you type the reply scroll down and read your own post. Do you see the signature? I don't.

I usually (re-)read the details of the post while replying. So I usually miss any info from the signature. (Besides, when you change it in the future, the people will be confused because they will think this thread belongs to a newer version.

 

TinyPortal © 2005-2018