* * *

Author Topic: Run Time Error only during exectution from the IDE  (Read 1340 times)

simone

  • Jr. Member
  • **
  • Posts: 73
Run Time Error only during exectution from the IDE
« on: April 19, 2017, 12:55:02 pm »
Hello everyone,

I have a strange behaviour with application I'm writing: If I run it from the IDE (F9) I get a runtime error when I close the application (External SIGSEGV). If I run the same application outside Lazarus, from the exe file, and I perform the same actions before closing, the runtime error dont'arise. It's difficult to give other information, since the application is relatively large and I cant't reproduce the code here. This phenomenon started after I introduced some instructions in a destructor, so I think is related to objects clean-up performed at the end of execution. Moreover I extensively use generics of FLG (in particular TFPGObjectList) that sometimes cause internal errors during compilation (that disappear after i purge the lib folder with binary files). Do you have some suggestions? Thanks in advance.

jmm72

  • Jr. Member
  • **
  • Posts: 79
  • Very experienced in being a beginner...
Re: Run Time Error only during exectution from the IDE
« Reply #1 on: April 20, 2017, 10:47:26 am »
That sounds like trying to access an object reference which was already freed. Try this: whenever you use whateverobject.Free, change it to use the function FreeAndNil(whateverobject). That not only frees the object, also sets the object reference to Nil. Also, when running in debug mode, when the SIGSEGV window appears and you close it, you should be stopped on the source line which caused the error.
Lazarus 1.6.4 + FPC 3.0.2 64bits under Windows 7 64bits
Only as a hobby nowadays
Current proyect release: TBA

Eugene Loza

  • Hero Member
  • *****
  • Posts: 531
    • My "almost daily" development blog
Re: Run Time Error only during exectution from the IDE
« Reply #2 on: April 20, 2017, 11:13:52 am »
Moreover I extensively use generics of FLG (in particular TFPGObjectList) that sometimes cause internal errors during compilation (that disappear after i purge the lib folder with binary files).
Looks like exactly the problem I was struggling a month ago. NEVER free TFPGObjectList elements BEFORE destroying the List iteslf.
E.g. the situation looks like.
You have a TFPGObjectList
You create and operate TFPGObjectList and finally you free (or the free is done automatically) some of its content.
You close the app.
It calls destructor which frees TFPGObjectList and it tries to access already freed memory area.
In case you are in IDE you'll see a SIGSEGV, in case you're in the OS you'll only see a console message.

How can this happen.

1.
You have two TFPGObjectList
Both have OWNS OBJECT = true;
They share some (one is enough) of their elements.
You free one of them. It frees all of its content.
You free another and it tries to access memory already freed. Therefore SIGSEGV.

2.
You have a TFPGObjectList with Owns objects = true
You add elements to it. However, you forget that the TFPGObjectList owns the object and try to manage some of those manually (even in case of exceptions/errors), or automatically (e.g. by TComponent ownership).
you get one of the TFPGObjectList elements freed (maybe in other destructor).
You close the app and TFPGObjectList tries to access memory already freed. Therefore SIGSEGV.

How to tell if that is the problem? Try setting OwnsObjects (I don't remember exact variable name) to false, which is most generally done by TFPGObjectList.create(false) instead of TFPGObjectList.create or TFPGObjectList.create(true);
If the error goes away into memory leaks then this is the case :)
Then just carefully scan your code against manually/automatic freeing elements of TFPGObjectList
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

simone

  • Jr. Member
  • **
  • Posts: 73
Re: Run Time Error only during exectution from the IDE
« Reply #3 on: April 20, 2017, 11:24:16 am »
Thank you. I'm going crazy... Now I follow your suggestions. If during execution from the IDE I 'detach from program', I have no runtime error at closing... There could be some strange interaction with GDB?

Eugene Loza

  • Hero Member
  • *****
  • Posts: 531
    • My "almost daily" development blog
Re: Run Time Error only during exectution from the IDE
« Reply #4 on: April 20, 2017, 11:37:13 am »
There could be some strange interaction with GDB?
Check your firewall/antivirus. They tend to hate GDB.
Especially that Comodo guy  >:D.
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

simone

  • Jr. Member
  • **
  • Posts: 73
Re: Run Time Error only during exectution from the IDE
« Reply #5 on: April 20, 2017, 11:44:42 am »
I disabled personal firewall... When I launch the application outside the IDE, no SIGSEGV... Very strange...

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5875
Re: Run Time Error only during exectution from the IDE
« Reply #6 on: April 20, 2017, 12:07:22 pm »
It might be that the debugger traps all exceptions, even the ones that are silenced in e.g. the application.onexception method.

You can configure somewhere which exception (types) the debugger should ignore.

simone

  • Jr. Member
  • **
  • Posts: 73
Re: Run Time Error only during exectution from the IDE
« Reply #7 on: April 20, 2017, 12:36:53 pm »
Unfortunely using FreeAndNil and disabling automatic freeing elements of TFPGObjectList don't resolve my problem... However if this is not due to a flaw in FGL or in DBG, I sadly deduce that something is wrong in my code...

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4417
    • wiki
Re: Run Time Error only during exectution from the IDE
« Reply #8 on: April 20, 2017, 04:49:57 pm »
There is also a chance that there is a bug in gdb, try http://wiki.lazarus.freepascal.org/GDB_Debugger_Tips#gdb.exe_has_stopped_working

simone

  • Jr. Member
  • **
  • Posts: 73
Re: Run Time Error only during exectution from the IDE
« Reply #9 on: April 20, 2017, 06:34:50 pm »
I have the same suspect about GDB... I rewrite the unit that give me the error using TObjectList in place of TFPGObjectList, and I have again the same problem... So this is not related to generics...

 

Recent

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