Recent

Author Topic: Run Time error on not existing line  (Read 772 times)

Birger52

  • Sr. Member
  • ****
  • Posts: 299
Run Time error on not existing line
« on: August 23, 2020, 01:23:10 pm »
I get a runtime SigSegv Error on line 996 of a unit the only has 112 lines.

Tried with and without begin ... end in initialization and finalization, as I don't know if they're supposed to be there (Don't think so - but then again - it apparently makes no difference...)
Tried with fpDebug installed an not installed - makes no difference either.

Compiles fine.

Any hints on where to look for the error - other than line 996 of a file that only has 112 lines?
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6721
  • Debugger - SynEdit - and more
    • wiki
Re: Run Time error on not existing line
« Reply #1 on: August 23, 2020, 02:08:03 pm »
Do you use generics? (specialize ...<>)?

If you are on fpc 3.0.4 and use generics this will happen.

Basically If you "specialize FooFromOtherUnit<x>", the compiler will take the line numbers that "Foo" has in its own unit, and puts them into your unit (maybe with offset, don't remember).


IIRC, that is fixed in 3.2.0

jamie

  • Hero Member
  • *****
  • Posts: 3797
Re: Run Time error on not existing line
« Reply #2 on: August 23, 2020, 02:53:54 pm »
The little I played with that IPC component I remember I could not set the ACTIVE property to true during design time and have it active when your app starts, it needs to be set to ACTIVE after everything in your app is ready.

 You could be having other issues but I would look there.
The only true wisdom is knowing you know nothing

Birger52

  • Sr. Member
  • ****
  • Posts: 299
Re: Run Time error on not existing line
« Reply #3 on: August 23, 2020, 07:10:37 pm »
Well - it's not IPC, since in this unit, the client is created at runtime, and not enabled.

But I do use specialize - that would be unit fgl then.
Will look into that...
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

Birger52

  • Sr. Member
  • ****
  • Posts: 299
Re: Run Time error on not existing line
« Reply #4 on: August 23, 2020, 07:36:24 pm »
Tried "unspecializing" - fairly simple to cast objects when needed.
First to TFPSList which give SigSegv errors on line 7 of this function
Code: Pascal  [Select][+][-]
  1. function TAppList.GetApp(aApp:string) : TAppObj;
  2. var
  3.   idx : integer = 0;
  4. begin
  5.   result := nil;
  6.   while (idx < Count) and not Assigned(result) do
  7.     if TAppObj(Items[idx]).Name = aApp then result := TAppObj(Items[idx])
  8.     else inc(idx);
  9. end;
  10.  
- which does not really make sense either.
So used a TList instead.
That works.

So unit fgl is basically useless?
Seems I have used generics before without problems. Not with initialization and finalization tho....
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6721
  • Debugger - SynEdit - and more
    • wiki
Re: Run Time error on not existing line
« Reply #5 on: August 23, 2020, 10:03:30 pm »
I do not know how exactly fpc 3.0.4  maps the line numbers during specialization.... (Its a bug in 3.0.4)

If you move in your unit, the "specialize" to another line, does the error occur at the same line? Or does in move?
In other words, I do not know if line 996
- is fgl.pas line 996
- or fgl.pal line 996 minus the line of the specialize in your unit.

I would guess the first.

Assuming
    TAppList = specialize TFPSList<...>
then
   "While idx < Count"
would segfault if self was nil. Or if self was some other uninitialized value (that points to mem not belonging to your app)

So the issue would be in the caller.
  assert(self <> nil);
But only if it is not trash...

debugln('Self in GetAPP %u', [PtrUInt(Self)]);
https://wiki.lazarus.freepascal.org/LazLogger

Birger52

  • Sr. Member
  • ****
  • Posts: 299
Re: Run Time error on not existing line
« Reply #6 on: August 24, 2020, 12:25:05 pm »
Appeciate the effort.

The original specialized list used was TFPGObjectList.
To "unspecialize" I first used The same and then TFPSList.
Both of them gave the error in the while idxx < Count line (actually the error pointed to the next line - comparing data in one var of one of the objects in the list - assuming debugger points to the correct line in this instance...)

So using TFPSList was not specialized...
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

jamie

  • Hero Member
  • *****
  • Posts: 3797
Re: Run Time error on not existing line
« Reply #7 on: August 24, 2020, 01:33:50 pm »
I don't know why FPC even has "Specialize" in the first place, is it so hard for the compiler to determine what to do ?

Also, I think a better word could have been picked "Establish" would of been my choice.


P.S.
  I wanted to note that GENERICS isn't your friend, especially when it comes to Casting.. Its a whole different world out there.
« Last Edit: August 24, 2020, 01:35:33 pm by jamie »
The only true wisdom is knowing you know nothing

PascalDragon

  • Hero Member
  • *****
  • Posts: 2435
  • Compiler Developer
Re: Run Time error on not existing line
« Reply #8 on: August 24, 2020, 02:10:28 pm »
I don't know why FPC even has "Specialize" in the first place, is it so hard for the compiler to determine what to do ?

Yes, it is. There's a reason why mode Delphi does not yet compile all kinds of inline specializations especially if used in expressions that don't consist of a single factor.

Birger52

  • Sr. Member
  • ****
  • Posts: 299
Re: Run Time error on not existing line
« Reply #9 on: August 29, 2020, 04:09:43 pm »
Well - I eventually chose not to use lists at all, as it will never be holding more than five or 6 items anyway.
Created an object that contains an array indexed by an enum and instances of common vars/other objects.
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

jamie

  • Hero Member
  • *****
  • Posts: 3797
Re: Run Time error on not existing line
« Reply #10 on: August 29, 2020, 05:10:16 pm »
You could of used TLIST, TCOllections etc..

That is assuming your items are Pointer based.
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018