Recent

Author Topic: "missing DisableAutoSizing" EInvalidOperation exception  (Read 8006 times)

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
"missing DisableAutoSizing" EInvalidOperation exception
« on: August 05, 2016, 09:41:01 am »
I have 32bit Lazarus application (actually CT 5.80) used in iron producing industry running 24/7 on Windows server 2003 R2 SP2, catching all unhandled exceptions. I have this exception being logged from time to time:
Quote
EInvalidOperation: TControl.EnableAutoSizing VisualisationForm:TVisualisationForm: missing DisableAutoSizing
All other exceptions are solved and there are no memory leaks left according to heaptrc reports. I would really appreciate If anyone can point me in good direction to fix this, since I am out of ideas.
:D  :o  :D

I have looked at LCL code for "missing DisableAutoSizing", and found it inside of "\lcl\include\control.inc":
Code: Pascal  [Select][+][-]
  1. procedure TControl.EnableAutoSizing
  2.   {$IFDEF DebugDisableAutoSizing}(const Reason: string){$ENDIF};
  3.  
  4.   {$IFDEF DebugDisableAutoSizing}
  5.   procedure CheckReason;
  6.   var
  7.     i: Integer;
  8.     s: String;
  9.   begin
  10.     i:=FAutoSizingLockReasons.Count-1;
  11.     while i>=0 do begin
  12.       if FAutoSizingLockReasons[i]=Reason then begin
  13.         FAutoSizingLockReasons.Delete(i);
  14.         exit;
  15.       end;
  16.       dec(i);
  17.     end;
  18.     s:='TControl.EnableAutoSizing '+DbgSName(Self)+' never disabled with reason "'+Reason+'"';
  19.     for i:=0 to FAutoSizingLockReasons.Count-1 do
  20.       s+=','+LineEnding+'reason['+IntToStr(i)+']="'+FAutoSizingLockReasons[i]+'"';
  21.     RaiseGDBException(s);
  22.   end;
  23.   {$ENDIF}
  24.  
  25. begin
  26.   {$IFDEF DebugDisableAutoSizing}
  27.   CheckReason;
  28.   {$ENDIF}
  29.  
  30.   if FAutoSizingLockCount<=0 then
  31.     raise EInvalidOperation.Create('TControl.EnableAutoSizing '+DbgSName(Self)+': missing DisableAutoSizing');
  32.  
  33.   dec(FAutoSizingLockCount);
  34.   //DebugLn([Space(FAutoSizingLockCount*2),'TControl.EnableAutoSizing ',DbgSName(Self),' ',FAutoSizingLockCount]);
  35.   if (FAutoSizingLockCount=0) then
  36.   begin
  37.     if (Parent<>nil) then
  38.     begin
  39.       //DebugLn([Space(FAutoSizingLockCount*2),'TControl.EnableAutoSizing ',DbgSName(Self),' enable Parent ',DbgSName(Parent)]);
  40.       Parent.EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.DisableAutoSizing'){$ENDIF};
  41.     end else
  42.       DoAllAutoSize;
  43.   end;
  44. end;
It looks suspicious but I might be totally wrong on this since I do not understand it enough to jump into any useful conclusion.

This is how my FormResize looks like (I have attached screenshot to make it more clear):
Code: Pascal  [Select][+][-]
  1. procedure TVisualisationForm.FormResize(Sender: TObject);
  2. var
  3.   i: byte;
  4. begin
  5.   try
  6.     if CommStatus.Panels.Count > 0 then
  7.       for i := 0 to CommStatus.Panels.Count - 1 do
  8.         CommStatus.Panels[i].Width := (CommStatus.Width + 2) div CommStatus.Panels.Count;
  9.  
  10.     for i := 0 to 5 do // BF1 leds
  11.       BlastFurnacePlcStatus.Panels[i].Width := ((BlastFurnacePlcStatus.Width + 4) div 2) div 6;
  12.     for i := 6 to 12 do // BF2 leds
  13.       BlastFurnacePlcStatus.Panels[i].Width := ((BlastFurnacePlcStatus.Width + 4) div 2) div 7;
  14.  
  15.     C7Grid.Width := Notebook.ActivePage.Width div 2; // we have to use ActivePage because inactive page width is not refreshed on form resize
  16.     BF1Grid.Width := C7Grid.Width;
  17.   except
  18.     on E: Exception do Logger.SendException('Exception during form resize', E);
  19.   end;
  20. end;

Unfrotunately I can not show all of the code and I was not able to isolate this in some small example because application can work even few weeks without exception being logged. I am open for all suggestions.
« Last Edit: August 05, 2016, 10:02:07 am by avra »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: "missing DisableAutoSizing" EInvalidOperation exception
« Reply #1 on: August 25, 2016, 10:28:13 pm »
Anyone?   :'(
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: "missing DisableAutoSizing" EInvalidOperation exception
« Reply #2 on: August 25, 2016, 10:59:09 pm »
You could try defining DebugDisableAutoSizing and see if it is clearer what might go wrong when a reason or reasons are then added to the error message.

Since this is production code, if you don't want CheckReason() to call  RaiseGDBException(s), you could temporarily patch control.inc to log the message "s" instead of raising a major error.

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: "missing DisableAutoSizing" EInvalidOperation exception
« Reply #3 on: August 29, 2016, 03:20:33 pm »
You could try defining DebugDisableAutoSizing and see if it is clearer what might go wrong

Thank you very much for looking at this problem! I put {$DEFINE DebugDisableAutoSizing} at the top of forms.pp (and the same is if I put it on the top of controls.pp, control.inc, or scrollingwincontrol.inc). After "Clean up and build" I get this: Error: Wrong number of parameters specified for call to "DisableAutoSizing". Here are the details:

Quote
Compile package FCL 5.8.1: Success
Compile package bs_Utils 5.8.2: Success, Warnings: 5, Hints: 9
lazfileutils.inc(387,18) Warning: Symbol "faSysFile" is not portable
lazfileutils.inc(389,17) Warning: Symbol "faHidden" is not portable
lazfileutils.inc(390,19) Warning: Symbol "faVolumeId" is deprecated
lazfileutils.inc(390,19) Warning: Symbol "faVolumeId" is not portable
lazfileutils.inc(391,18) Warning: Symbol "faSymLink" is not portable
lazlistclasses.pas(501,126) Hint: Mixing signed expressions and longwords gives a 64bit result
lazlistclasses.pas(611,116) Hint: Mixing signed expressions and longwords gives a 64bit result
lazlistclasses.pas(652,71) Hint: Mixing signed expressions and longwords gives a 64bit result
lazlistclasses.pas(654,143) Hint: Mixing signed expressions and longwords gives a 64bit result
lazlistclasses.pas(799,27) Hint: Mixing signed expressions and longwords gives a 64bit result
lazlistclasses.pas(1236,43) Hint: Mixing signed expressions and longwords gives a 64bit result
lazlistclasses.pas(1639,20) Hint: Mixing signed expressions and longwords gives a 64bit result
lazlistclasses.pas(1236,43) Hint: Mixing signed expressions and longwords gives a 64bit result
lazlistclasses.pas(1639,20) Hint: Mixing signed expressions and longwords gives a 64bit result
Compile package pl_win_oledb 5.2.1: Success
Compile package pl_synapse 40.1.11: Success, Warnings: 4, Hints: 20
synautil.pas(637,96) Warning: Symbol "TimeSeparator" is deprecated
synautil.pas(1981,3) Note: Local variable "BackStop" is assigned but never used
synautil.pas(2121,88) Warning: Symbol "ShortMonthNames" is deprecated
synautil.pas(2122,87) Warning: Symbol "ShortMonthNames" is deprecated
synautil.pas(89,22) Hint: Unit "synafpc" not used in synautil
asn1util.pas(333,18) Warning: Local variable "s" of a managed type does not seem to be initialized
synacode.pas(1295,14) Hint: Local type "Pinteger" is not used
blcksock.pas(2984,51) Hint: Mixing signed expressions and longwords gives a 64bit result
blcksock.pas(4343,47) Hint: Variable "WsaDataOnce" does not seem to be initialized
pingsend.pas(430,30) Hint: Mixing signed expressions and longwords gives a 64bit result
synacrypt.pas(1992,3) Note: Local variable "n" not used
synacrypt.pas(69,32) Hint: Unit "synafpc" not used in synacrypt
snmpsend.pas(813,19) Hint: Converting the operands to "Int64" before doing the add could prevent overflow errors.
snmpsend.pas(1160,3) Note: Local variable "col" is assigned but never used
ssl_openssl_lib.pas(932,32) Hint: C arrays are passed by reference
ssl_openssl_lib.pas(933,32) Hint: C arrays are passed by reference
ssl_openssl_lib.pas(933,49) Hint: C arrays are passed by reference
ssl_openssl_lib.pas(934,30) Hint: C arrays are passed by reference
ssl_openssl_lib.pas(934,49) Hint: C arrays are passed by reference
ssl_openssl_lib.pas(934,69) Hint: C arrays are passed by reference
ssl_openssl_lib.pas(877,27) Hint: Local type "TSSLSetTlsextHostName" is not used
synadbg.pas(60,51) Hint: Unit "synafpc" not used in synadbg
synamisc.pas(165,25) Hint: Local type "PTIP_ADDRESS_STRING" is not used
synaser.pas(122,3) Hint: Unit "synafpc" not used in synaser
Compile package LCLBase 5.8.1: Exit code 1, Errors: 15
scrollingwincontrol.inc(21,93) Error: Wrong number of parameters specified for call to "DisableAutoSizing"
controls.pp(1514,15) Error: Found declaration: DisableAutoSizing;
scrollingwincontrol.inc(26,94) Error: Wrong number of parameters specified for call to "EnableAutoSizing"
controls.pp(1515,15) Error: Found declaration: EnableAutoSizing;
customform.inc(199,84) Error: Wrong number of parameters specified for call to "DisableAutoSizing"
controls.pp(1514,15) Error: Found declaration: DisableAutoSizing;
customform.inc(1020,91) Error: Wrong number of parameters specified for call to "EnableAutoSizing"
controls.pp(1515,15) Error: Found declaration: EnableAutoSizing;
customform.inc(1201,84) Error: Wrong number of parameters specified for call to "DisableAutoSizing"
controls.pp(1514,15) Error: Found declaration: DisableAutoSizing;
customform.inc(1208,85) Error: Wrong number of parameters specified for call to "EnableAutoSizing"
controls.pp(1515,15) Error: Found declaration: EnableAutoSizing;
customform.inc(1716,34) Error: Identifier not found "WriteAutoSizeReasons"
customform.inc(2696,92) Error: Wrong number of parameters specified for call to "DisableAutoSizing"
controls.pp(1514,15) Error: Found declaration: DisableAutoSizing;
Compile package bs_CodeTools 5.8.1: Aborted
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: "missing DisableAutoSizing" EInvalidOperation exception
« Reply #4 on: August 29, 2016, 03:42:52 pm »
After putting {$DEFINE DebugDisableAutoSizing} at the top of about 15 files, and after fixing 2 forgotten IFDEFs in code, compilation was a success. I will leave it running on my dev pc to see if exceptions shows up. Thanks!
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: "missing DisableAutoSizing" EInvalidOperation exception
« Reply #5 on: September 08, 2016, 09:58:09 am »
Unfortunatelly {$DEFINE DebugDisableAutoSizing} didn't help at all, because suddenly hundreds of memory leaks show and I have never succeeded to run such leaked executable for more then an hour and since sometimes weeks are needed for exception to show I never had a chance to catch it.

Well, my production application runs 24/7 quite fine for months now. I will just have to live with logs having this single exception caught from time to time. It doesn't affect production so I will let it be. No perfection this time.

Thanks howardpc for participating and everyone else for reading!
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

Zoran

  • Hero Member
  • *****
  • Posts: 1830
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: "missing DisableAutoSizing" EInvalidOperation exception
« Reply #6 on: September 08, 2016, 02:34:27 pm »
After putting {$DEFINE DebugDisableAutoSizing} at the top of about 15 files, and after fixing 2 forgotten IFDEFs in code, compilation was a success. I will leave it running on my dev pc to see if exceptions shows up. Thanks!

Instead of putting this define to many files, you can put one line to project options. This is as if you added this define in each file which gets compiled with the project.

From main menu, go to Project->Project Options... Then in tree view select Custom Options and add line -dDebugDisableAutoSizing (see attached picture).

Not that I can help with this problem you have, sorry...

ASerge

  • Hero Member
  • *****
  • Posts: 2242
Re: "missing DisableAutoSizing" EInvalidOperation exception
« Reply #7 on: September 08, 2016, 03:31:22 pm »
...Unfrotunately I can not show all of the code and I was not able to isolate this in some small example because application can work even few weeks without exception being logged. I am open for all suggestions.
May be GUI used not in the main thread? As a result the pair of Inc(FAutoSizingLockCount), Dec(FAutoSizingLockCount) sometimes breaks (simultaneous access to a single variable)

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: "missing DisableAutoSizing" EInvalidOperation exception
« Reply #8 on: September 09, 2016, 09:12:58 am »
Instead of putting this define to many files, you can put one line to project options. This is as if you added this define in each file which gets compiled with the project.
Before your clarification I had wrong domain asumption about putting define into project options. Thanks Zoran for pointing this out!
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: "missing DisableAutoSizing" EInvalidOperation exception
« Reply #9 on: September 09, 2016, 09:27:11 am »
May be GUI used not in the main thread? As a result the pair of Inc(FAutoSizingLockCount), Dec(FAutoSizingLockCount) sometimes breaks (simultaneous access to a single variable)
You nailed me with this one! I have two worker threads who besides their job do just one nasty thing - they each update a different single resizable label. I thought that I could get away with this, but now with your help I see that it may just be the root of the problem. I will further investigate and change this part of the code to fully play by the book. Hopefully that will fix it.
Thanks a lot ASerge, you made my day!   :D ;) :D
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

Zoran

  • Hero Member
  • *****
  • Posts: 1830
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: "missing DisableAutoSizing" EInvalidOperation exception
« Reply #10 on: September 09, 2016, 11:25:49 am »
You nailed me with this one! I have two worker threads who besides their job do just one nasty thing - they each update a different single resizable label.

Wrap this updating of the labels in Synchronize method. See http://delphi.about.com/od/kbthread/a/thread-gui.htm.

 

TinyPortal © 2005-2018