Lazarus

Using the Lazarus IDE => Editor => Topic started by: Nicole on April 30, 2025, 04:27:31 pm

Title: IDE crashes and takes so much code with it
Post by: Nicole on April 30, 2025, 04:27:31 pm
 >:(
In the last weeks, I lost code and code and code after not having saved every 2 minutes.
I make a severe mistake, which puzzles the compiler. e.g. I write one "end;" too many (see screenshot)
This is sever, yes.
But is this a reason to kill the whole IDE without giving me any chance to save it?

Below is the error message and attached a screenshot of a "lost my work again"-situation.

Code: Text  [Select][+][-]
  1. [Window Title]
  2. project_Tiger (C:\Tiger) - Lazarus-IDE v3.0
  3.  
  4. [Content]
  5. Kann Methode nicht zeigen Please fix the error shown in the message window which is normally below the source editor.
  6.  
  7. Press OK to ignore and risk data corruption.
  8. Press Abort to kill the program.
  9.  
  10. [Ok] [Abbruch]
  11. [Content]
  12. Kann Methode nicht zeigen Please fix the error shown in the message window which is normally below the source editor.
  13. Press OK to ignore and risk data corruption.
  14. Press Abort to kill the program.
  15. [Ok] [Abbruch]
Title: Re: IDE crashes and takes so much code with it
Post by: Bart on April 30, 2025, 04:30:29 pm
It's a CodeTools error.
(You're trying to complete some code?)
Just click OK (not Abort), you should be fine (most of the time), click Save All after that, just to be on the safe side.

Bart
Title: Re: IDE crashes and takes so much code with it
Post by: 440bx on April 30, 2025, 04:41:03 pm
Nicole,

There is a package that will autosave your work.  That might be helpful to ensure you don't lose a significant amount of work.

Read about it at: https://forum.lazarus.freepascal.org/index.php/topic,68028.msg525335.html#msg525335

HTH.
Title: Re: IDE crashes and takes so much code with it
Post by: Nicole on April 30, 2025, 08:35:46 pm
Thank you for the link.

about autosave:
There is something which is even worse then a IDE-crashing. This is a programmer, who writes nonsense until she is stuck.
Sometimes I click somewhere and suddenly items are gone, lost, whatever. Then I click "close unit", "save?" - no, no no!


Title: Re: IDE crashes and takes so much code with it
Post by: Martin_fr on April 30, 2025, 08:49:04 pm
It would be good to find the cause of the crash.

Never mind what you throw at the editor or codetools (or any other part of the IDE), it may report errors but should not crash....

Unfortunately with the info given in this thread, there is nothing to find the cause.

Obviously (or maybe not obvious, but still) it hasn't happen to members of the dev team. They would have likely had reported it (among the team) with at least a stack trace. I am not aware of such a report.

Also not aware of anyone else reporting it. So whatever it is, it may be bound to something particular in your setup, and that may mean that it can only be fixed with help from your side.



For starters it would be good if you could build the ide with the following options in
Tools > Configure build IDE
Code: Text  [Select][+][-]
  1. -gw -gl -Criot

Then run the IDE with
Code: Text  [Select][+][-]
  1. --debug-log=c:\lazarus\log.txt
(or whatever path is appropriate for your setup)

After a crash, the file would very hopefully contain a stacktrace (among lots of other stuff).

That stacktrace may be helpful, at least for an initial hint where to go looking further.



Additionally it may be good to take a backup of your "primary config path"
Menu: view > ide internals > about IDE
It will have files like codetoolsoptions.xml and environmentoptions.xml and editoroptions.xml.
Those may be important if the error is bound to specific settings.

Backing up the folder makes sure they will be avail, should it turn out that they are needed.



Last but not least (actually should be first)

What version of Lazarus are you using?

Your OS seems Windows? If you don't mind which version and 32/64bit?

And, what packages do you have installed?
(IIRC should be listed in staticpackages.inc in the primary conf dir)

Title: Re: IDE crashes and takes so much code with it
Post by: Nicole on May 02, 2025, 09:30:28 pm
If I would be able to reproduce, I would do.
This "start with", it is too much to me.
I am no programmer, code-writing is just a need-fulfilling, because I need a function I cannot buy anywhere.

However I will do my best, to help the community, which gave me that much:
My Lazarus is 3.0
It runs under a Win 7 VM, 64 bit.

Attached are 2 files:
a) the file you mentioned
b) a really strange thing of an warning. The translation to English means: "Warning, double files". I deleted them often, but the next test there are there again.
I have no idea, what this means. Usually ambiguity rarely means a good thing. And the file the message mentions, I cannot find it.
Title: Re: IDE crashes and takes so much code with it
Post by: CharlyTango on May 03, 2025, 11:09:03 am
Over the years, more and more safety functions have been built into every car. And yet serious, even fatal accidents still happen.

It's no different in IT, which is why a staggered backup strategy is used at the latest after a vital crash.

Everyone has their own ideal solution.
For example, I have the code in a directory that is synchronised with a private cloud. The moment the file changes on the disc, it is copied to the cloud as a primary backup.
Since this cloud also has the option of managing different versions of a file, this is already a
pretty basic solution.

I also use a version control system that is triggered manually to keep versions together.

To keep this performant, all object files are stored in a different directory.

Unit Output Directory:
C:\Laz_Lib\<projectname>\$(TargetCPU)-$(TargetOS)-$(LazVer)

In addition, there are at least 2 (in my case with all test installed versions rather 12) complete Lazarus installations.

If it really kills my IDE, I have at least one other working installation ready with which I can continue working while the faulty instance is deleted and reinstalled in the background.

Of course, this doesn't help against all events, but it does help against a large part of them

Title: Re: IDE crashes and takes so much code with it
Post by: Martin_fr on May 03, 2025, 11:51:32 am
I don't know all the packages you have installed. Though at first sight non is particular suspicious. Yet, even the best code can crash. => So they need to be considered as potentially being the cause for the crash (as does the rest of the IDE).

But from the given data, I can't really tell anything. There are a million lines of code in the IDE, and any of them could be the culprit.

1) You can upgrade (4.0 is due soon). If you are lucky it goes away.
Even Lazarus 3.8 may be worth a shot. But now you might wait, as 4.0 is around the corner.

There are 18 commits between 3.0 and 3.8 that explicitly fix some crash (there may be more, but they don't include the word crash in the message). Not all of them are happening on Windows. But 2 or 3 do.

2) If not, then a trace is needed (or at least its the simplest way of getting any further clue.

You already rebuild your IDE for the packages you added. So no magic there.
- Make a copy of your current "lazarus.exe" (c:\lazarus\lazarus.exe or where ever you installed yours). So you can always restore this, if needed.
- Open the "Tools" menu, go to "Configure build lazarus". There is a text field (memo) "Options". Add (without the quotes): " -O-1 -gw -gl -Criot ". Then press build
- Restart the IDE
- Close the IDE
- On Windows: Create a shortcut on the desktop, and right click it, and choose "properties". In the field "target" it gives the path+name of the exe, add (with a leading space)  --debug-log=c:\lazlog.txt

Now you can start the IDE via that shortcut.
If it hasn't crashed, then occasionally (before starting) remove the old logfile. (or it will grow really large).
When it has crashed, submit the logfile (or the last 200 lines, if it is to large / or zip it).

Title: Re: IDE crashes and takes so much code with it
Post by: Nicole on May 03, 2025, 01:34:17 pm
Thank you.
I was not aware, there is 3.8. I thought 3.4 would be the lastest.
I'll wait for 4.

My plans are to leave Windows. There is a lot of code to write as I will have to substitute a whole software packed I bought years ago, which never will work with Wine. Then I will start with Linux and Lazarus 4. Cross fingers, it is not 5 in the meanwhile.
Title: Re: IDE crashes and takes so much code with it
Post by: Nicole on May 06, 2025, 09:20:27 pm
@ Martin_fr

I thought over it.
If you do not experience problems, then I suspect it is due to a working habit. Probably I use anything of copy, paste, fix names, add,.... which is not in your workflow.

In other words: What may cause troubles is the graphic environment of the IDE on work in progress. My idea would be: teach the IDE to send you an error report on unplanned ending at development time.

A very weak position are begin and end and lost headers.
Under old Delphi I once searched for loooong for an extremely unpleasant bug. It took me an eternity to find it. It was nothing but a ";" too many, lost in some unit head part.

Just one sign for a man, an intersection for a compiler.  8-)

Title: Re: IDE crashes and takes so much code with it
Post by: Martin_fr on May 06, 2025, 09:41:05 pm
We don't have an automatic error upload.

And not every user would want that. In fact some user would not be able to use an IDE that did this, because automatic uploads may contain private data, and some people work on company secrets.

Also, such an uploader may not always work, if the crash is to bad, and skips it.

What we have is the ability to write logfiles, that most often contain a first clue. I gave you details on how to do that.
Takes less than 10 minutes to setup
- Menu: Tools > Configure build IDE: with custom options   -O-1 -gw -gl -Criot
- 1 to 4 minutes for the IDE to rebuild
- exit IDE
- 1 to 2 minutes to create and edit the desktop shortcut
- Start working, until crash
- 1 minute to zip and upload the file

----------
Btw 4.0 is out, and avail for download.
Title: Re: IDE crashes and takes so much code with it
Post by: Nicole on May 07, 2025, 09:18:59 pm
Yes, this is true.
There are a lot of private data in my code as well. E.g. my authorization keys for several quite expensive services.
Now, as you say it...

Thank you for the instruction, I saved them.
Title: Re: IDE crashes and takes so much code with it
Post by: munair on May 10, 2025, 09:05:44 am
I'm amazed to read this. I have been coding for years, even large projects and I can't remember Lazarus crashing on me, certainly not in recent years. And quite often I make mistakes angering code tools. Just wondering, could this be an OS issue? I've been doing most of the coding on Linux (Debian and Manjaro) using GTK2 and Lazarus seems quite stable there. I'm also in the bad habit of hitting ctrl+s frequently. But that's because I'm more afraid of sudden power outage.
Title: Re: IDE crashes and takes so much code with it
Post by: Nicole on May 20, 2025, 07:46:02 pm
Sure, this can be.
At the moment, I use a Win 7 VM.

These crashes occur in interaction with the visual environment at design time. e.g. If I want to place an item on a different frame or to a different panel I have two options: I can copy it, - but the names change to +1. So my edit_item will become edit_item1. Only on cutting the item instead will cause the names not to change.

So I cut it, - if the pasting does not work, bye bye... they are gone. Some panels are the work of hours and days! Every crucial re-arranging I do a full backup before, which is crazy. I have hundreds of backups, which I have to delete in bundles from time to time.

Win 7 may be the problem. But as well, there can be a problem with VMWare or the graphic-driver. Windows has some very nasty and very fuzzy issues. They are indeed rare, this is why it is so hard to catch them. All in all it is a really good operating system. However, I will say bye bye to it because I refuse Win 11.
Title: Re: IDE crashes and takes so much code with it
Post by: 440bx on May 20, 2025, 08:33:29 pm
I'm amazed to read this. I have been coding for years, even large projects and I can't remember Lazarus crashing on me, certainly not in recent years.
I had it crash twice yesterday but, I agree it is very rare for it to crash.  I know the reason of the crash is the same in both cases: codetools, it crashes when asked to locate a particular function (there is nothing special about the function other than codetools not "liking" it.)

I didn't report it because, while the two programs are tiny (less than 200 lines), they use my Windows API definitions, which I'm currently working on, which are in the ballpark of 300,000 lines that are several megabytes even after 7zipping them, which is a lot larger than what the forum allows. Not to mention that those files are currently in a state of flux since I'm working on them.

Maybe it's just a coincidence that this crash also happens in Win 7 SP1 running in a VM just as in Nicole's case.

Title: Re: IDE crashes and takes so much code with it
Post by: munair on May 21, 2025, 04:27:25 pm
At the moment, I use a Win 7 VM.
...
Win 7 may be the problem. But as well, there can be a problem with VMWare or the graphic-driver. Windows has some very nasty and very fuzzy issues. They are indeed rare, this is why it is so hard to catch them. All in all it is a really good operating system. However, I will say bye bye to it because I refuse Win 11.

I also use Lazarus on Windows 7 (next to Linux), but on a dedicated machine and not in a VM. I have no problems.
Title: Re: IDE crashes and takes so much code with it
Post by: munair on May 21, 2025, 04:32:23 pm
At the moment, I use a Win 7 VM.
...
Win 7 may be the problem. But as well, there can be a problem with VMWare or the graphic-driver. Windows has some very nasty and very fuzzy issues. They are indeed rare, this is why it is so hard to catch them. All in all it is a really good operating system. However, I will say bye bye to it because I refuse Win 11.

I also use Lazarus on Windows 7 (next to Linux), but on a dedicated machine and not in a VM. I have no problems. However, I do most of the coding on Linux. I can't say I've been heavy testing on W7.
Title: Re: IDE crashes and takes so much code with it
Post by: Nicole on May 21, 2025, 04:33:20 pm
I am not sure, what codetools means. However the word suggests, that it may be similar to a situation I came across several times:

I like developing by using existing code. For this, I copy whole methods and paste them to create something new with their lines. There is a lot to be aware of: Give them a new name, care for a not existing name, place it somewhere into context with other functions within the class. Be aware of begin and end in every loop. Very helpful is that I made the IDE drawing a line under every method. If the "end;" is under this line, it is a severe warning of messed loop.

In this work, it happens frequently that anything gets messed. e.g. I forget to delete a
functiion TMyClass.myMethod: TmyIdea; or a begin end block is lost. Or the click-event from one button shall be copied to the event for another button and this is messed.

Sure, in this case the compiler is puzzled.  Worse, if I try to double-click a button to jump to its click-event to fix it. In the best case, the IDE says "I cannot hop there". In the worst case, ... bye bye IDE, bye bye all changes of the last hour... How to file it? It is gone!

Logging it all and every tiny second does not pay.
So I hit "save" every some minutes. The prize is, that the build-in backup function of Lazarus is worthless, because I save too often for it.
Title: Re: IDE crashes and takes so much code with it
Post by: Nicole on May 21, 2025, 04:58:10 pm
in the best case this is helpful or anybody is familiar with it:

 This was my situation:
 I had a line reading
Code: Pascal  [Select][+][-]
  1.  jsonText, s: string;

 if should read:
Code: Pascal  [Select][+][-]
  1.  jsonText: string;

 my mistake, i deleted more than ",s and the line ended up:
Code: Pascal  [Select][+][-]
  1.  jsonText;
(as you see it on the screenshot)
 
 The compiler says it and it is easy to fix.
BUT:  I did not see it in time.

I clicked at designtime to ANY click event of a speed button.
 This click event has nothing in common with the messed method.
 
 This is such a case of bye bye.

 Be aware: I do not expect to be able to reproduce this by myself.
 I am not quite sure, which circumstances must meet. It hits me when I do not expect it.
 This screenshot is what I can provide and hoping anybody finds it helpful.
 

 
Title: Re: IDE crashes and takes so much code with it
Post by: munair on May 21, 2025, 05:51:54 pm
Codetools pops up frequently here, but it's on Linux and I can't remember it crashing the IDE. It seems like this is a Windows thing or VM related.
Title: Re: IDE crashes and takes so much code with it
Post by: Martin_fr on May 21, 2025, 06:26:16 pm
I am not sure, what codetools means. However the word suggests, that it may be similar to a situation I came across several times:
Most features that need to "understand" pascal.

Most well known: code completion (the drop down, but also creating local vars...).
It also does refactoring from the menu.
And it does automatic insertion of "end" if you press return after a new "begin".
And it can do some indent, if set up to do...

Quote

I like developing by using existing code. For this, I copy whole methods and paste them to create something new with their lines.
When you paste, does your code get re-indented?

That would be codetools (first page of codetools options).

And quite a few people may have that "smart indent" turned off. So that would be a feature only some (not sure how many, could be half, could be 75% or 25%....) users would use.

It then may also depend on what that code contains.

There are a few known issue (albeit not sure about crashes) when codetool encounters generics...


Quote
There is a lot to be aware of: Give them a new name, care for a not existing name, place it somewhere into context with other functions within the class. Be aware of begin and end in every loop. Very helpful is that I made the IDE drawing a line under every method. If the "end;" is under this line, it is a severe warning of messed loop.
The lines are the highlighter / that is not codetools.

The highlighter is the 2nd part of the IDE that understands Pascal.


Quote
In this work, it happens frequently that anything gets messed. e.g. I forget to delete a
functiion TMyClass.myMethod: TmyIdea; or a begin end block is lost. Or the click-event from one button shall be copied to the event for another button and this is messed.

In which case you probably start getting errors from codetools when you try to "jump to declaration/implementation", or complete code. Watch the IDE's messages window.

Mind that this also may severely affect the designer, especially when you try to create new events (OnClick, etc).

Quote
Sure, in this case the compiler is puzzled.  Worse, if I try to double-click a button to jump to its click-event to fix it. In the best case, the IDE says "I cannot hop there". In the worst case, ... bye bye IDE, bye bye all changes of the last hour... How to file it? It is gone!

Yes, that be a complicated case.

Because it may not just be the state immediately before. It may be which other states the IDE has been in. There are caches that can go wrong.

But a first point is trying to get a stack trace.
That might at least allow to circumvent the crash, and have an error instead.  (At least it improves chances that can be done)


If the IDE runs with a logfile, it may still be able to write that trace.
If it does not, it will be more work. It would mean to run the IDE in the debugger, until it crashes.



You are on Windows?

In the lazarus folder open "cmd.exe"
(In the windows explorer, while looking at the folder replace the directory in the edit with "cmd.exe" and press return)

Then run  (you need full path to gdb which is inside lazarus install mingw\gdb)
    gdb  -ex r -ex bt ./lazarus

You may need to confirm "Enable debuginfod for this session? (y or [n]) " with N if it asks.

When lazarus crashes it should show a stacktrace.

You can put that in a .bat file (but someone needs to check how to disable the debuginfod quesiton)

TinyPortal © 2005-2018