"missing DisableAutoSizing" EInvalidOperation exception lazarus / 31-LCL ---------------------------------------------------------------------- avra · 2016-08-05 07:41 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: QuoteEInvalidOperation: TControl.EnableAutoSizing VisualisationForm:TVisualisationForm: missing DisableAutoSizingAll 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.     I have looked at LCL code for "missing DisableAutoSizing", and found it inside of "\lcl\include\control.inc": Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TControl.EnableAutoSizing  {$IFDEF DebugDisableAutoSizing}(const Reason: string){$ENDIF};   {$IFDEF DebugDisableAutoSizing}  procedure CheckReason;  var    i: Integer;    s: String;  begin    i:=FAutoSizingLockReasons.Count-1;    while i>=0 do begin      if FAutoSizingLockReasons[i]=Reason then begin        FAutoSizingLockReasons.Delete(i);        exit;      end;      dec(i);    end;    s:='TControl.EnableAutoSizing '+DbgSName(Self)+' never disabled with reason "'+Reason+'"';    for i:=0 to FAutoSizingLockReasons.Count-1 do      s+=','+LineEnding+'reason['+Int ToStr(i)+']="'+FAutoSizingLockReasons[i]+'"';    RaiseGDBException(s);  end;  {$ENDIF} begin  {$IFDEF DebugDisableAutoSizing}  CheckReason;  {$ENDIF}   if FAutoSizingLockCount<=0 then    raise EInvalidOperation.Create('TControl.EnableAutoSizing '+DbgSName(Self)+': missing DisableAutoSizing');   dec(FAutoSizingLockCount);  //DebugLn([Space(FAutoSizingLockCount*2),'TControl.EnableAutoSizing ',DbgSName(Self),' ',FAutoSizingLockCount]);  if (FAutoSizingLockCount=0) then  begin    if (Parent<>nil) then    begin      //DebugLn([Space(FAutoSizingLockCount*2),'TControl.EnableAutoSizing ',DbgSName(Self),' enable Parent ',DbgSName(Parent)]);      Parent.EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.DisableAutoSizing'){$ENDIF};    end else      DoAllAutoSize;  end;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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TVisualisationForm.FormResize(Sender: TObject);var  i: byte;begin  try    if CommStatus.Panels.Count > 0 then      for i := 0 to CommStatus.Panels.Count - 1 do        CommStatus.Panels[i].Width := (CommStatus.Width + 2) div CommStatus.Panels.Count;     for i := 0 to 5 do // BF1 leds      BlastFurnacePlcStatus.Panels[i].Width := ((BlastFurnacePlcStatus.Width + 4) div 2) div 6;    for i := 6 to 12 do // BF2 leds      BlastFurnacePlcStatus.Panels[i].Width := ((BlastFurnacePlcStatus.Width + 4) div 2) div 7;     C7Grid.Width := Notebook.ActivePage.Width div 2; // we have to use ActivePage because inactive page width is not refreshed on form resize    BF1Grid.Width := C7Grid.Width;  except    on E: Exception do Logger.SendException('Exception during form resize', E);  end;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. ---------------------------------------------------------------------- avra · 2016-08-25 20:28 Anyone? ---------------------------------------------------------------------- howardpc · 2016-08-25 20:59 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 · 2016-08-29 13:20 Quote from: howardpc on August 25, 2016, 10:59:09 pmYou 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: QuoteCompile 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 ---------------------------------------------------------------------- avra · 2016-08-29 13:42 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! ---------------------------------------------------------------------- avra · 2016-09-08 07:58 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! ---------------------------------------------------------------------- Zoran · 2016-09-08 12:34 Quote from: avra on August 29, 2016, 03:42:52 pmAfter 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 · 2016-09-08 13:31 Quote from: avra on August 05, 2016, 09:41:01 am...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 · 2016-09-09 07:12 Quote from: Zoran on September 08, 2016, 02:34:27 pmInstead 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! ---------------------------------------------------------------------- avra · 2016-09-09 07:27 Quote from: ASerge on September 08, 2016, 03:31:22 pmMay 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! ---------------------------------------------------------------------- Zoran · 2016-09-09 09:25 Quote from: avra on September 09, 2016, 09:27:11 amYou 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.