Recent

Author Topic: Strange effect with form DockedFormEditor  (Read 6406 times)

prof7bit

  • Full Member
  • ***
  • Posts: 161
Strange effect with form DockedFormEditor
« on: September 24, 2021, 03:26:33 pm »
I assume it is DockedFormEditor because I started using it a month ago and I am experiencing this strange effect since about a month ago.

I cannot test without DockedFormEditor because since I made the step towards a docked IDE I cannot ever work without it again. The bug requires me to work a few hours until it appears.

The issue is very hard to pinpoint, on some days it won't happen at all and sometimes it happens on every save of the form.

The issue is it occasionally inserts completely wrong (usually much too small) values for ClientWidth and ClientHeight into the lfm. The effect is that controls that are anchored at the bottom or right will be cut of at the bottom and the right. It looks as if someone took a pair of scissors and cut a few centimeters off of the form on the right and on the bottom.

Code: [Select]
object FMain: TFMain
  Left = 372
  Height = 611
  Top = 240
  Width = 1092
  Caption = 'XECRO Inductive Calibrator'
  ClientHeight = 251                      // <-- here
  ClientWidth = 412                       // <-- here
  Constraints.MinHeight = 600
  Constraints.MinWidth = 1000
  DesignTimePPI = 92

  ...

Above is an example of how it looks after it happened. The form should be 1092 x 611 and normally the same values should be in ClientWidth and ClientHeight but occasionally (not always and not with all forms!) when I save the form after I made an unrelated change to some property it will insert these wrong values.

I close the IDE, reset the messed up lfm contents from my version control and restart the IDE, try the same edit in the same form and it happens again.

I close the IDE, I close a lot of editor tabs and other forms and then the problem is gone for the rest of the day.

I open all the other forms again and the problem does not reappear again for the rest of the day.

The next day suddenly it starts happening again.

I have not yet filed a bug because I cannot come up with a set of steps to reproduce it.

Did anbody else observe similar probelms?
« Last Edit: September 24, 2021, 03:48:15 pm by prof7bit »

prof7bit

  • Full Member
  • ***
  • Posts: 161
Re: Strange effect with form DockedFormEditor
« Reply #1 on: September 24, 2021, 08:01:41 pm »
One thing I have also noticed:

The Property LCLVersion keeps appearing and disappearing in the .lfm file at random times. I always notice it when it pops up as change in my git commit tool. This has been going on for weeks now.

I know that the DockedFormEditor does NOT write LCLVersion into the file while the built in form editor does. But I also know for sure that I did not ever use an undocked IDE anymore for at least 4 weeks!

prof7bit

  • Full Member
  • ***
  • Posts: 161
Re: Strange effect with form DockedFormEditor
« Reply #2 on: September 29, 2021, 05:04:13 pm »
Today I noticed that the problem seems to be strongly correlated to the LCLVersion effect, and I also suspec the "save all with i18n" has some connection with it:

* I made a few changes in the resource strings of another unit (not a form) of my project: nothing bad happened. I committed the changed .pot file, no changes in the lfm.
* I made a few changes in the resourcestrings of the main form: the following happened:
  - The LCLVersion appeared in the .lfm (although i have docked form editor)
  - The ClientWidth/Height were corrupted again

* Clossed the form/unit and opened it again
* I made a small change and saved it again: LCLVersion disappeared, Clientsize correct again.

So to me it seems something (possibly to do with i18n) is triggering some code from the built-in form designer instead of their replacement from dockedformdesigner to save the form and that code gets some values wrong or misbehaves while dockedformdesigner is running.

DockedFormDesigner does not save LCLVersion to the .lfm file while built-in form designer does. So I can imediately see who has saved the form. 99% of the time there is no LCLVersion, so only DockedFormDesigner is running and saving my form (as it should be because this has been the only running IDE the whole day long), but under some circumstances suddenly the LCLVersion appears in the lfm and this is also exactly the time when the size mismatch happens!

prof7bit

  • Full Member
  • ***
  • Posts: 161
Re: Strange effect with form DockedFormEditor
« Reply #3 on: September 29, 2021, 05:13:43 pm »
Wow! Just now I noticed it just changed and corrupted the lfm of a form I had not opened or modified for more than a year (it is kind of a splash screen)! It also wrote the LCLVersion to the file.

It has to be the i18n thing!  Because the entire day I was only extracting resource strings and translating, occasional saving and recompiling, I made no other changes anywhere!

Michl

  • Full Member
  • ***
  • Posts: 226
Re: Strange effect with form DockedFormEditor
« Reply #4 on: September 30, 2021, 11:20:54 am »
I missed this thread. Thank you for your hints. I'll have a look at this.

I can confirm, sometimes the LCLVersion is saved in the .lfm. Also sometimes, this info is removed. This is nothing special of DockedFormEditor but of IDE. It only happens more often with this package, as it always generates the designer of a form (also if you are just typing some letters in code and don't open tab "Form").

For your first problem, I need to know: Do you use a High-DPI-Environment? You can check this if you open a form. What is the entry of DesignTimePPI?
Code: [Select]
type
  TLiveSelection = (lsMoney, lsChilds, lsTime);
  TLive = Array[0..1] of TLiveSelection;

prof7bit

  • Full Member
  • ***
  • Posts: 161
Re: Strange effect with form DockedFormEditor
« Reply #5 on: September 30, 2021, 02:43:42 pm »
Regarding your question: I used to work with 92 DPI for a while, this was caused by the proprietary nvidia driver, this was annoying, I have now fixed the dpi at my development workstation to 96 with xrandr and now Lazarus reliably gets the 96 every time.

But this does not seem to be related, it still keeps happening in my 96DPI environment with forms saved with 96dpi.

Some new observations from today:

* DPI awareness and scaling is enabled, Designtime DPI is (and remains) at 96
* i18n is enabled, resourcestrings also exist in the code.
* I have my project committed in git, so I can immediately see if files changed.
* The project has 3 forms:
    ->  all of them have been saved with dockedformeditor
    ->  none of them contains LCLVersion
    ->  Client size is still correct in all forms.
* project is committed to git in exactly that state, so I can reset whenever I need.

* Lazarus is closed.
* I start Lazarus, it loads the project.
* run | build   -> git diff shows no changes to any files
* Project | resave forms with i18n
    -> LCLVersion inserted in all 3 forms,
    -> 1 out of 3 forms has messed up client size (251*412 instead of 611*1092)

* close Lazarus
* git reset --hard

* I start Lazarus, it loads the project
* I rebuild Lazarus without DockedFormEditor
* It restarts and loads the project again
    -> still no changes in git diff, project is still untouched
* Project | resave forms with i18n
    -> LCLVersion inserted in all 3 forms
    -> everything else remains untouched, no corruption

* close Lazarus
* git reset --hard

* I start Lazarus, it loads the project
* rebuild Lazarus with DockedFormEditor
* It restarts and loads the project again
    -> project is still untouched
* Project | resave forms with i18n
    -> LCLVersion inserted in all 3 forms
    -> same form as above has the exact same wrong values in client size

(repeating the above steps as I type it)

The form has a TChart on it, a bunch of Buttons, some TStaticTexts, a TMemo and a TRadioGroup. Chart is anchored on all 4 sides, buttons are ancored bottom right, memo is anchored top, left, bottom. Radiogroup and TStaticTexts are anchored top,left.

The TRadioGroup also has ClientHeight and ClientWidth and these are also changed, but not as dramatic as the values of the form.

One of the other forms that did not corrupt (today) also has a tchart with anchors on all 4 sides on it.

----

I also have a small demo project with some elements on a form for trying to provoke the problem there, so far no success. I am making all kinds of changes there, playing with anchors and panels, closely watching the git diff after every step and committing every tiny little change, and as soon as I manage to get it into the same state where it corrupts right after opening I will post it and also file a bug, because then I can provide steps to reproduce. But so far no luck.
« Last Edit: September 30, 2021, 03:04:33 pm by prof7bit »

prof7bit

  • Full Member
  • ***
  • Posts: 161
Re: Strange effect with form DockedFormEditor
« Reply #6 on: September 30, 2021, 03:29:59 pm »
One more observation:

* Lazarus is closed, DockedFormEditor is installed.
* project files are reset to the state above

* I start Lazarus, it loads the project
* I change 1 letter in the code of the offending form (not in the design!)
* I hit Ctrl + S (save)
    -> LCLVersion is inserted into lfm (only this form, others untouched)
    -> client size is corrupted as above

* I do NOT restart Lazarus now
* I do NOT reset from git

* .lfm is still in the freshly corrupted state
* I click the form tab
* In the object inspector I change the witdh from 1092 to 1091, hit <enter>
* Click Save button in toobar
* In the object inspector I change the width from 1091 back to 1092, hit <enter>
* Click Save button in toobar

* corruption disappears, lfm file disappears from git diff, is back in original state!

* I make another small change in the code (like above) and Ctrl + S
    -> NO corruption
* Project | resave forms with i18n
    -> NO corruption
* now I can work on the project without further corruption. Until I close and reopen Lazarus.



« Last Edit: September 30, 2021, 03:36:44 pm by prof7bit »

prof7bit

  • Full Member
  • ***
  • Posts: 161
Re: Strange effect with form DockedFormEditor
« Reply #7 on: September 30, 2021, 04:00:16 pm »
And the last one for today (probably)

* Project is reset in the state as above
* Start Lazarus, it loads the project
* Click on the form tab of the offending form (DockedFormEditor)

* change a property
* save it
    -> No corruption
* change it back to where it was
* save it
    -> No corruption
    -> file is clean again
* Project | Resave with i18n
    -> LCLVersion appears
    -> No corruption
* Change the code and save
   -> No corruption

* Change a property with DockedFormEditor and save
    -> LCLVersion disappears
    -> No corruption

* Edit some more code
    -> no corruption

----------

So it seems to me the corruption can only ever happen when
  * Lazarus just has been started
  * The DockedFormEditor has not yet been used
  * the form was saved because of i18n
  * the form was saved because of code change in form unit

As soon as DockedFormEditor has been used only just once the problem completely disappears!

Final and most important observation:

* Project is reset as above
* Start Lazarus, it opens the project
* Click on every form in the source editor and click on the form tab, just click the tab to show the formeditor, nothing else!
* Project | Resave with i18n
    -> no corruption
    -> not even LCLVersion, files remain unchanged!
* Edit code in the form units and save
    -> lfm files remain unchanged!

So as soon as the dockedformeditor has been shown (for each form) just once the problem disappears for the rest of the session until I restart Lazarus. Some initialization seems to be missed!





« Last Edit: September 30, 2021, 04:02:52 pm by prof7bit »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: Strange effect with form DockedFormEditor
« Reply #8 on: September 30, 2021, 05:54:01 pm »
LCLVersion should be saved with both form editors IMO. It depends on the version of LCL and nothing else.
The corruption issue is caused by something else of course.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

prof7bit

  • Full Member
  • ***
  • Posts: 161
Re: Strange effect with form DockedFormEditor
« Reply #9 on: September 30, 2021, 06:55:04 pm »
LCLVersion should be saved with both form editors IMO.
Yes, but currently it serves as some kind of hint or marker when it is executing one code path or the other. And the occasional appearance of LCLVersion correlates 100% with the appearance of the lfm corruption, maybe it helps coming closer to the underlying cause of this strange behavior.
« Last Edit: September 30, 2021, 07:06:11 pm by prof7bit »

prof7bit

  • Full Member
  • ***
  • Posts: 161
Re: Strange effect with form DockedFormEditor
« Reply #10 on: October 01, 2021, 10:59:52 am »
Got it! Can now reliably demonstrate the bug:
https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39409

Please try and see if you can reproduce.

prof7bit

  • Full Member
  • ***
  • Posts: 161
Re: Strange effect with form DockedFormEditor
« Reply #11 on: October 12, 2021, 11:24:21 am »
Could already somebody reproduce the issue with my example project?

Meanwhile I have found one more that is easier to reproduce, it seems somhow related although this time it also involves DPI scaling, I added it to the bug report:

https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39409#note_701183272

The visible symptoms are the same: some controls are growing absurdly large, larger than the form itself, like the first example it only seems to happen when minwidth/minsize is set, but this time no unusual things happen to clientwidth/clientheight and this time it also happens immediately when shown in dockedformeditor, I have not yet found a way to avoid this corruption other than manually editing the DesignTimePPI with a text editor before attempting to open it in DockedFormeditor, otherwise corruption is guaranteed.

Please tell me if anybody can at least reproduce my problems with these examples.

prof7bit

  • Full Member
  • ***
  • Posts: 161
Re: Strange effect with form DockedFormEditor
« Reply #12 on: October 12, 2021, 11:38:00 am »
It seems this issue only appears on Qt5
I just tested on GTK2 and nothing unusual happens

 

TinyPortal © 2005-2018