Recent

Author Topic: Wierd behaviour - Laz 1.6 >> Laz 2.2  (Read 12304 times)

J-G

  • Hero Member
  • *****
  • Posts: 966
Re: Wierd behaviour - Laz 1.6 >> Laz 2.2
« Reply #30 on: September 14, 2022, 12:12:40 pm »
I'm no further forward but I have been busy testing - this is just an update.

Whenever I have a problem such as this I try to look at it logically which essentially means that whatever the last [Edit] was, ought to be the root cause. In this case I opened the previously working project in Laz 2.2 and added some a TEdit, 2 TLabels and a TButton with an associated [Event].

To determine whether these additions were the cause, I've spent some time adding them to the original Laz 1.6 version - compiling after each element was added in an attempt to isolate the offending item. Unfortunately each compilation completed and the program ran as expected  ???  %)

So, at least I do have a version of the program which incorporates the updates I need (occasioned by the demands of the VAT Man!)  but I would still like to be able to compile under Laz 2.2 / FPC 3.2.2
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

J-G

  • Hero Member
  • *****
  • Posts: 966
Re: Wierd behaviour - Laz 1.6 >> Laz 2.2
« Reply #31 on: September 14, 2022, 12:14:57 pm »
Whoever he is, I've got his profile open so I can see promptly if he starts dumping spam.

MarkMLl
Thanks for the backup Mark  -  the post just looked odd ??

Mind you,  seeing the thread title   :D :D
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11926
  • Debugger - SynEdit - and more
    • wiki
Re: Wierd behaviour - Laz 1.6 >> Laz 2.2
« Reply #32 on: September 14, 2022, 12:26:43 pm »
Ok, more confused....

Your first msg
Quote
even with a debugging break at the very first line of [FormCreate] fired a 'ShowMessage'
Not sure if that is still happening, but now you seem to reach your main form....

I can only add another guess.

Maybe the exact timing at which some of the events fire has changed. E.g. Some  OnChange fires, but your code still sees the empty control.... (where as before it would have seen the change).
Then you need to find which event(s), and debug into them, and see with what to replace them...


I mention again: switch optimization off. FPC 3.2.2 has some optimizer bugs.
They are very rare to affect some code... but ....






J-G

  • Hero Member
  • *****
  • Posts: 966
Re: Wierd behaviour - Laz 1.6 >> Laz 2.2
« Reply #33 on: September 14, 2022, 07:28:23 pm »
Ok, more confused....
Apologies for that Martin :(
Quote from: Martin_fr
Your first msg
Quote
even with a debugging break at the very first line of [FormCreate] fired a 'ShowMessage'
Not sure if that is still happening, but now you seem to reach your main form....
Yes it is still happening and NO I don't reach the main Form.

The image I attached of the main Form was created under Laz 1.6. Only the CallStack etc. displays were under Laz 2.2

Quote from: Martin_fr
I can only add another guess.

Maybe the exact timing at which some of the events fire has changed. E.g. Some  OnChange fires, but your code still sees the empty control.... (where as before it would have seen the change).
Then you need to find which event(s), and debug into them, and see with what to replace them...

I mention again: switch optimization off. FPC 3.2.2 has some optimizer bugs.
They are very rare to affect some code... but ....
I've just checked to be 100% sure, but yes, optimization IS turned off.

HOWEVER !!  --  Prompted by your suggestion  --  I've searched for [OnChange] events, of which there are 12, but only one visible on the main Form at start up (and therefore has the 'DATA Not Initialized'  test). -- The offending object is a TDateEdit -- By putting a breakpoint in that OnChange Proc. I've discovered that it is being fired before the Application.Run (which would show the main Form)!

As a test, I commented out the call to display the 'DATA Not Initialized' message - though still exiting the proc. - but (predictably) it still ends up at the 331 Error. - which I still have no knowledge of -   ::)

How is it possible for a procedure buried deep in the .PAS file (line 7061) to be called before the .LPR file has been fully processed ?   -  or, probably more to the point, what can I do to stop it doing so?!


FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

MarkMLl

  • Hero Member
  • *****
  • Posts: 8515
Re: Wierd behaviour - Laz 1.6 >> Laz 2.2
« Reply #34 on: September 14, 2022, 07:33:01 pm »
How is it possible for a procedure buried deep in the .PAS file (line 7061) to be called before the .LPR file has been fully processed ?   -  or, probably more to the point, what can I do to stop it doing so?!

Eddies in the spacetime continuum.

AKA something being called from an OnCreate() event handler.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

J-G

  • Hero Member
  • *****
  • Posts: 966
Re: Wierd behaviour - Laz 1.6 >> Laz 2.2
« Reply #35 on: September 14, 2022, 07:51:04 pm »
Eddies in the spacetime continuum.

AKA something being called from an OnCreate() event handler.

MarkMLl
Whilst I appreciate the humour, Mark, where do I look for the 'OnCreate' Event Handler ?
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11926
  • Debugger - SynEdit - and more
    • wiki
Re: Wierd behaviour - Laz 1.6 >> Laz 2.2
« Reply #36 on: September 14, 2022, 07:57:24 pm »
Maybe a 3rd party package has optimization on??

Project >Project Options > Additions and Overrides
- "stored in project"
- Add > New Target
  enter:  *
- Add >  custom option
  enter: -O-  -gw

This will rebuild all packages with no optimization and with debug info.
(except for the RTL / fcl packages)




I've searched for [OnChange] events, of which there are 12, but only one visible on the main Form at start up (and therefore has the 'DATA Not Initialized'  test). -- The offending object is a TDateEdit -- By putting a breakpoint in that OnChange Proc. I've discovered that it is being fired before the Application.Run (which would show the main Form)!
Before Application.run is strange. (before Form.Oncreate would be possible)

Do you have the trace for that?

When you look at the frames, going back from your proc, to the caller, and then to the caller's caller ......
Does each Caller actually have an invocation for the called callee?
Or is the (displayed) stack corrupt?

Continued below....


Quote
I commented out the call to display the 'DATA Not Initialized' message - though still exiting the proc. - but (predictably) it still ends up at the 331 Error. - which I still have no knowledge of -   ::)
Do you have an FPC/RTL build with debug info? Then you could set a breakpoint in the "exit" code

E.g. in unit system
Procedure fpc_do_exit;[Public,Alias:'FPC_DO_EXIT']; compilerproc;



Quote
How is it possible for a procedure buried deep in the .PAS file (line 7061) to be called before the .LPR file has been fully processed ?   -  or, probably more to the point, what can I do to stop it doing so?!

...Continued

There is a possibility of memory corruption (stack, code, data,...)
In this case it would be possible that the address of the called proc ends up somewhere (like the stack, or in a proc pointer) by pure chance. And so the proc would be called, but as a result of an error much earlier.

Let's try to get the cleanest build possible.

* Open the 1.6 IDE
- Open your project
- Menu: Project > Publish Project
  Give a new folder as "destination directory"
  Do not compress.

* Do not open your project before mentioned

* Close the old IDE.
- If you want to go the extra mile:
  rename the folder in which the old IDE (and FPC) are.
  >>>> DO NOT open the old IDE, until you undone the renaming <<<<


* Delete Lazarus 2.2 and Fpc 3.2.2
- Reinstall them => as 2ndary installation
  chose a new empty folder for config
- Install each and every package that your project needs.
  When you open the package check the path in the  status bar to be in the Lazarus 2.2 install
  For OPM packages: to be in the config folder

- If you rebuild the IDE => do so without optimizations.

- Now open the published project in you 2.2.x IDE

Build and test.


------
How private is the project. (and how many 3rd party packages does it need).
If it doesn't have too many requirements, could you send it privately?

MarkMLl

  • Hero Member
  • *****
  • Posts: 8515
Re: Wierd behaviour - Laz 1.6 >> Laz 2.2
« Reply #37 on: September 14, 2022, 09:07:08 pm »
Whilst I appreciate the humour, Mark, where do I look for the 'OnCreate' Event Handler ?
[/quote]

All forms etc. in the project.

There's a whole lot of things that aren't initialised properly until the final form/component/etc. has been created and the message loop is running. As such a change in unit etc. initialisation order, determined partly but not I believe entirely by the order of the units in the uses section, can break stuff.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

J-G

  • Hero Member
  • *****
  • Posts: 966
Re: Wierd behaviour - Laz 1.6 >> Laz 2.2
« Reply #38 on: September 15, 2022, 10:07:36 am »
Maybe a 3rd party package has optimization on??

Project >Project Options > Additions and Overrides
- "stored in project"
- Add > New Target
  enter:  *
- Add >  custom option
  enter: -O-  -gw

This will rebuild all packages with no optimization and with debug info.
(except for the RTL / fcl packages)

Hmmm  --- that didn't go well !!

I went through this process last night (or rather about 1am) and since I know that it can take some time to do a complete re-build I left it doing-its-thing. This morning - some 7 hours later - it has not completed and most keyboard activity is un-responsive. (the Run & Pause Icons are greyed out but Stop is active - but doesn't respond to a mouse click other than indicating that it has seen the click)  I say 'most' keyboard activity, things like [Ctrl][F2] and [F9] have no effect but I can type into the Object Inspector 'filter' but only in lower case - ie. caps lock nor shift change the case.  Selection of components (mouse click) doesn't show the 'handles' but I can add a new component and use upper case in the [Caption].  %)

Attached is a ScreenGrab of the Messages Window as it is (and was at 1am) in case that means anything.

I'll look at the other suggestions, though I have already created an isolated copy of the Accounts Prog for testing under Laz 2.2  so I may well install FPC/Laz on a Win 10 PC that has never had them on before. That will take some time and thought since I'll also have to consider the historic data.

[EDIT]
!! Forgot to mention that I use only one Form but at 'Design Time' it is two screens wide > 2400px 
« Last Edit: September 15, 2022, 12:53:06 pm by J-G »
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

J-G

  • Hero Member
  • *****
  • Posts: 966
Re: Wierd behaviour - Laz 1.6 >> Laz 2.2
« Reply #39 on: September 15, 2022, 11:39:16 am »
I've searched for [OnChange] events, of which there are 12, but only one visible on the main Form at start up (and therefore has the 'DATA Not Initialized'  test). -- The offending object is a TDateEdit -- By putting a breakpoint in that OnChange Proc. I've discovered that it is being fired before the Application.Run (which would show the main Form)!
Before Application.run is strange. (before Form.Oncreate would be possible)

I hope I haven't confused you further Martin. By 'Before Application.run' I mean that I set a breakpoint at line 4 in this code (from the .LPR):  ie. before  'Application.Run'
Code: Pascal  [Select][+][-]
  1. begin
  2.   RequireDerivedFormResource:=True;
  3.   Application.Initialize;
  4.   Application.CreateForm(TForm1, Form1);  // BreakPoint
  5.   Application.Run;
  6. end.
  7.  
Once this break is reached and I use either [F7] or [F8] to continue, this is when the 'DATA Not Initialized' message (from line 7068 in the .PAS file) fires.

Quote from: Martin_fr
Do you have the trace for that?
By 'trace' do you mean a list of code lines called? or is there some report created that I could look at and maybe attach?  I can't test and therefore trace at the moment since I'm still not sure that Laz has completed its re-build - I haven't closed it yet (I have removed the Custom setting) which seems to be the only way to release the 'lock'.

Quote from: Martin_fr
When you look at the frames, going back from your proc, to the caller, and then to the caller's caller ......
Does each Caller actually have an invocation for the called callee?
Or is the (displayed) stack corrupt?

I'm sure you'll not be surprised to hear that  -  after reading that paragraph a number of times  -  I am no wiser as to the meaning  :D :D :-[  Sorry  :(

[...]  for the sake of brevity.
Dealing with that suggestion will take me some time.

Quote from: Martin_fr
------
How private is the project. (and how many 3rd party packages does it need).
If it doesn't have too many requirements, could you send it privately?
Naturally since it is my company accounts, there is 'sensitive' information and I would have to look for potential security issues but I don't have a problem 'in principle'. 

Here is the [Uses] Clause:
Code: Pascal  [Select][+][-]
  1. uses
  2.   Classes, SysUtils, FileUtil, Windows,
  3.   RTTICtrls, PrintersDlgs, Forms,
  4.   Printers, Controls, Graphics, Dialogs,
  5.   StdCtrls, EditBtn, ExtCtrls, Arrow,
  6.   Grids, ActnList, Menus, DateUtils,
  7.   LCLIntf, Buttons, ComCtrls, JGDT
  8.   ;
  9.  
JGDT is my own Unit for dealing with Date & Time matters so I have the source code for that which I could create a simple .ZIP file of.

Other than that, the attached .PNG  shows the 'required packages'  and no doubt you would need some data files.


FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11926
  • Debugger - SynEdit - and more
    • wiki
Re: Wierd behaviour - Laz 1.6 >> Laz 2.2
« Reply #40 on: September 15, 2022, 01:17:09 pm »
Long Rebuild:

Compiling LazUtils shouldn't take that long. So maybe the build stopped and the IDE did not notice.
The Windows task manager should tell you, if there is a "ppc..." process, and if it is using cpu.

It also shouldn't take huge amount of mem. The only issue with huge mem usage that I am aware of, is linking the final project with "smart linking" enabled. If you do that with the IDE, it could take some memory.
- "smart linking" or "link smart" -XX only affects the project, not packages2
- "smart linkable" -CX  does not matter (afaik)

However, if you are really short on mem, you can go to Tools > Options: "Message Window" and on that page set "Maximum parallel processes ..." to 1.
Running only one instance of fpc at a time, needs less memory.


Stack / Stacktrace / trace / frames / Stackframe(s) / callers / caller-list ...

All refer to the list of callers as displayed by menu: View > Debug Windows > Call Stack

A frame (in this context) is a single entry from that list.

Quote
When you look at the frames, going back from your proc, to the caller, and then to the caller's caller ......
Does each Caller actually have an invocation for the called callee?
Or is the (displayed) stack corrupt?

So normally if the "Call Stack" has
Code: Text  [Select][+][-]
  1. #0 TForm1.FormCreate at unit1.pas:33
  2. #1 TCustomForm.DoCreate at lcl\include\customform.inc:921
  3. #2 TCustomForm.AfterConstruction at lcl\include\customform.inc:77

You can double click on the 2nd line, and it takes you to the code
Code: Pascal  [Select][+][-]
  1.     if Assigned(FOnCreate) then FOnCreate(Self);
That code has a function invokation "FOnCreate()".
It is plausible that this called "FormCreate"

And double clicking on AfterConstruction shows the code
Code: Pascal  [Select][+][-]
  1.   DoCreate;
Which is correct, because the callstack says that it called "DoCreate".

But.... sometimes you click on such a line, and there is no call. Not even if you look a few lines up or down.
Sometimes the line and unit don't even match the function name.

Exception:
Sometimes there is another call "Foo()" and "Foo" then contains the correct call. That is ok-ish. But if there is no call, or no call that could connect the call-stack entries...

Then it is possible that the stack got corrupted.
I.e. Maybe some code wrote past the end of an array, destroying other data...

So that is why I asked, if you do get a callstack, then verify it's integrity.


BrunoK

  • Hero Member
  • *****
  • Posts: 756
  • Retired programmer
Re: Wierd behaviour - Laz 1.6 >> Laz 2.2
« Reply #41 on: September 15, 2022, 03:25:25 pm »
Once this break is reached and I use either [F7] or [F8] to continue, this is when the 'DATA Not Initialized' message (from line 7068 in the .PAS file) fires.
Toggle a break point at that line 7068 and look where from it is reached (stack trace).

It is quite likely that you have a TForm1.OnCreate event/method that changes (UI event such as Click or assigning a value to an edit control.text) a non fully and instantiated TWinControl descendant. (Mostly in Win -> handle not yet allocated).

If that is the case, you should consider moving the problematic code to TForm1.OnShow or TForm1.OnActivate event/method as suitable.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11926
  • Debugger - SynEdit - and more
    • wiki
Re: Wierd behaviour - Laz 1.6 >> Laz 2.2
« Reply #42 on: September 15, 2022, 03:43:55 pm »
 A few other more or less generic pointers.

I would hope/guess that you did throw the usual debug options at your code -CRriot -Sa -gt  -gh

You should ensure they also apply to packages => see my earlier post on "Additions and Overrides" in Project Options.

-gt  can be given as either -gt -gtt -gttt or -gtttt
Each testing for something different, but they can not be mixed. One at a time only. So build and run 4 times


Using -gh you can go to "Run > Run Params" and add the environment
HEAPTRC=keepreleased

That can help detecting some memory errors. But don't run the app for too many hours, as it will eat memory over time.



Depending on how Linux savvy you are, there is valgrind.

If you can get Linux (eg. in a virtual machine), and your app compiles under Linux => then you can use valgrind. This is like -Criot on steroids.
I can extend on the subject of valgrind, if you consider that step.




J-G

  • Hero Member
  • *****
  • Posts: 966
Re: Wierd behaviour - Laz 1.6 >> Laz 2.2
« Reply #43 on: September 15, 2022, 04:47:02 pm »
Once this break is reached and I use either [F7] or [F8] to continue, this is when the 'DATA Not Initialized' message (from line 7068 in the .PAS file) fires.
Toggle a break point at that line 7068 and look where from it is reached (stack trace).
Thanks for the input Bruno,  I've had that [Break] in place for some time and a CallStack showing what has happened up to that point is attached.

I've had to re-boot my PC to stop the IDE Re-Build since even responding [Yes] when asked to stop the re-build, didn't !   -   Once Laz was then 'live' again I removed the requirement for JuJiBoUtils (in case that might have been the cause of the issue - it seems that it wasn't - and in fact there are no TJxxxx components in the project) and opened the project which still fired the break at 7067 (I was one line out :( )

Regrettably the information in the CallStack is beyond my comprehension  :-[  but it may tell someone else what I might try next.

Quote from: BrunoK
It is quite likely that you have a TForm1.OnCreate event/method that changes (UI event such as Click or assigning a value to an edit control.text) a non fully and instantiated TWinControl descendant. (Mostly in Win -> handle not yet allocated).

If that is the case, you should consider moving the problematic code to TForm1.OnShow or TForm1.OnActivate event/method as suitable.

I've commented out the TaxPointChange Proc and created a TaxPointEditingDone [Event] with the expectation that the problem would move to that Event (or, hopefully, go away!) but now it moves to a completely unrelated 'DatePaidChange' event and eventually to the same exit-code 331.

A second CallStack at the point of the new break point is also attached.
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

BrunoK

  • Hero Member
  • *****
  • Posts: 756
  • Retired programmer
Re: Wierd behaviour - Laz 1.6 >> Laz 2.2
« Reply #44 on: September 15, 2022, 06:01:50 pm »
What do you do in salesledger.pas at lines 7067 and 7488 ? What is the code there ? I'm sure you have in DatePaid.OnChange or TaxPointe.OnChange, a SetFocus or something similar that requires the form to be completely activated.

MOVE the pascal code that changes control contents in Form.OnCreate to Form.OnActivate. You may need to add, to TForm1, a boolean field to indicate if it has already been done once such as FActivated : boolean.

 

TinyPortal © 2005-2018