Forum > LCL
[Solved]Weird AV in the LCL on app-close...
cdbc:
Hi
All of a sudden, an ugly exception has begun to appear, when I close/free a TTabSheet containing a TFrame containing a TListView. It appears to be Font related as the fpdebugger takes me to: TFont.FreeReference; namely this piece of code:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TResourceCacheItem.DecreaseRefCount; procedure RaiseRefCountZero; begin RaiseGDBException('TResourceCacheItem.DecreaseRefCount=0 '+ClassName); end; begin //debugln('TResourceCacheItem.DecreaseRefCount ',ClassName,' ',dbgs(Self),' ',dbgs(FReferenceCount)); if FReferenceCount = 0 then <--- I land here with the debugger ? ! ? RaiseRefCountZero; dec(FReferenceCount); if FReferenceCount = 0 then Cache.ItemUnused(Self); //debugln('TResourceCacheItem.DecreaseRefCount END ');end; I have NO MonkeyBusiness going on, none whatsoever, just 3 event-handlers:
- OnDblClick
- OnKeyDown
- OnSelectItem
Would it perhaps be of any use, to disconnect them just before it all gets freed?!? (never had to do that before, but there's a first time for everything, I guess).
If I step it further in the debugger/cpuwindow everything around it seems to be nil...
For now I've wrapped the dang thing in exception handlers and the "DivisionByZero" exception from"RaiseGDBException" changes into an Access Violation when I can catch it.
It's safe to say, it annoys the h*** out of me :'(
I'd be much obliged for any help you can give me :)
Regards Benny
d4eva:
Can you create a small, reproducible code example? It's hard to help without seeing the actual code.
cdbc:
Hi
Well it's quite intricate, involving a lot of busines-logic behind the scenes...
But I can show you the code where the culprit resides:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- procedure TfrmLedger.pctMainCloseTabClicked(Sender: TObject);var Dt: ptrint; Pg: TTabSheet; Fr: TfraListview; Fracc: TfraListview_acc;begin { this is used, when we want to free a page on tab-close-button-click } Pg:= Sender as TTabSheet; { we get the perpetrator served on a silver platter } if Pg.Name = 'tabSettings' then exit; { swallow event, we don't want to close 'Settings' } Pg.OnShow:= nil; { we're freeing it anyway } Dt:= StrToInt(Pg.Hint); { get our datatype from otherwise unused hint prop } case Dt of 0,2: begin Fr:= TfraListview(Pg.Tag); { does it contain a frame? one could also simply do: TfraListview(Pg.FindChildControl('fraListview')) :o) } if Fr <> nil then begin { we haven't necessarily used fTextSearch, but if we have... } if Assigned(fTextSearch) then begin if Fr.Bom <> nil then fTextSearch.DetachDataset(Pg.Caption,Fr.GetBomIntf) { detach ourselves from textsearch } else fTextSearch.DetachDataset(Pg.Caption,nil); { bom already freed, detach to avoid AV } end; Fr.Fini; { if so, call its "destructor" } end; end; 1: begin Fracc:= TfraListview_acc(Pg.Tag); { does it contain a frame? one could also simply do: TfraListview(Pg.FindChildControl('fraListview')) :o) } if Fracc <> nil then begin { we haven't necessarily used fTextSearch, but if we have... } if Assigned(fTextSearch) then begin if Fracc.Bom <> nil then fTextSearch.DetachDataset(Pg.Caption,Fracc.GetBomIntf) { detach ourselves from textsearch } else fTextSearch.DetachDataset(Pg.Caption,nil); { bom already freed, detach to avoid AV } end; Fracc.Fini; { if so, call its "destructor" } end; end; end; // case if KKLOptions.RemoveItemOnClose then RemoveFileFromMainView(Pg.Caption); { and finally remove it formerly FreeAndNil(Pg); now Pg.Free; } {$ifdef debug} ErrorLog.LogLn('TfrmLedger.pctMainCloseTabClicked: Freeing Pg '+Pg.Caption+' @ '+DateTimeToStr(now+0.0417)); {$endif} try Pg.Free; except on E: Exception do //// <<--- Here Pg.Free; raises an AV begin ErrorLog.LogLn('Error! TfrmLedger.pctMainCloseTabClicked @ '+DateTimeToStr(now+0.0417)+#10+E.Message); end; end;end;{$undef debug}
This is what the log looks like:
--- Quote ---TfrmLedger.pctMainCloseTabClicked: Freeing Pg 1000_kasse-03.2023 @ 12-3-23 11:04:50
Error! TfrmLedger.pctMainCloseTabClicked @ 12-3-23 11:04:50
Access violation
--- End quote ---
Everything is fine until Pg.Free; But it is not everytime it raises AV, just kinda when it feels like it. The frames are all alike.
Regards Benny
Bart:
If you do Application.ReleaseComponent(Pg) instead of Pg.Free, does that help?
Bart
jamie:
I remember something about the TTabSheet's property TAG was being used for internal use and it was questioned before, but I don't remember it ever being solved.
This would mean it's possible the TAG property is changing one way or the other.
Looking at Laz docs I don't see it in the published list but it is in there for Delphi, this is a bug That I remember that no one wanted to cover, I guess.
Navigation
[0] Message Index
[#] Next page