Recent

Author Topic: Cryptic errormessage  (Read 1385 times)

Birger52

  • Sr. Member
  • ****
  • Posts: 309
Cryptic errormessage
« on: November 16, 2019, 01:51:20 pm »
I have a descendant of TObjectList.
It holds descandants af TThread.
Code: Pascal  [Select][+][-]
  1. constructor TThumbLoaderList.Create(aMax:integer);
  2. begin
  3.   inherited Create(false);
  4.   OwnsObjects := false;
  5.   FMaxActive := aMax;
  6.   FActive := 0;
  7. end;
At some point, I need to clear the list.
Code: Pascal  [Select][+][-]
  1. procedure TThumbLoaderList.Clear;
  2. begin
  3.   while Count > 0 do Remove(Items[0]);
  4. //  inherited Clear;
  5.   FActive := 0;
  6. end;    
Originally, I used the Inherited. It gives an error, when removing the last (I think) object:
List Index out of Bounds (x)
Which does not make sense - why does it try to remove an item not there?
So I wrote my own clear - simply removing the first item, until none is left.
It gives the same error:
List Index out of Bounds (x)
- even tho noone asked it to remove the x'th index, only the 0'th.

Any explanations or workaround?
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

Birger52

  • Sr. Member
  • ****
  • Posts: 309
Re: Cryptic errormessage
« Reply #1 on: November 16, 2019, 02:24:06 pm »
Turns out, the error is correct - but it is another list another places in the source...

May be, this is connected to Step Over(F8) does not always necessarily actually Step Over, nor Step Into(F7) actually makes debugging Step Into when Debugging in IDE.
Any way to reset IDE?
(Resetting Debugger and/or recompiling, makes no difference...)
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Cryptic errormessage
« Reply #2 on: November 16, 2019, 05:35:36 pm »
Did you try running it without debugging ?

Also, are any of those threads doing any deleting on the Object list ?
The only true wisdom is knowing you know nothing

Birger52

  • Sr. Member
  • ****
  • Posts: 309
Re: Cryptic errormessage
« Reply #3 on: November 17, 2019, 01:58:01 pm »
No, I didn't try without debugging, for this error, but did for something else.
(Try .. except stops debugging, even if "exception" is handled - and it also terminates program if it thinks the exception is fatal)

Nothing is deleting anything.
Objects are removed from the ObjectList, but they are freeing themselves (TThread FreeOn Terminate).
Object list has OwnObjects set to false, so it simply removes a pointer to an object.

Problem is solved, correcting the real error - and so far so good.
Lazarus shouldn't report an error another place in the source, than where it actually occurs.
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Cryptic errormessage
« Reply #4 on: November 17, 2019, 04:24:59 pm »
If you are working with threads then your app is exactly at the line of the exception - but not in your main thread. Threads are not easy to debug!

Winni

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Cryptic errormessage
« Reply #5 on: November 17, 2019, 05:22:09 pm »
One of the threads must be accessing it maybe while deleting them..

could a  CriticalSection fix this problem ?
The only true wisdom is knowing you know nothing

Birger52

  • Sr. Member
  • ****
  • Posts: 309
Re: Cryptic errormessage
« Reply #6 on: November 18, 2019, 07:47:44 pm »
Threads are loading imagefiles - and not accessing main thread in any way.
Reading the file into a TBitMap with the right dimensions - that is later drawn to screen by main thread.
So the error doesn't have anything to do with the Threads.

As stated earlier, the error is actually in another thread, at a different point in the main thread.
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

 

TinyPortal © 2005-2018