Access violation at @UStrClr

delphi package - automated exception handling
Post Reply
chkaufmann
Posts: 12
Joined: Fri Dec 11, 2009 10:57 am

Access violation at @UStrClr

Post by chkaufmann »

Hi,

I try to isolate an error:

Code: Select all

exception class    : EAccessViolation
exception message  : Access violation at address 0040B438 in module 'Logo12.exe'. Read of address 3FDFFFF8.

main thread ($ac4):
0040b438 Logo12.exe System           24262 @UStrClr
0040d140 Logo12.exe System           31492 @FinalizeArray
0040d064 Logo12.exe System           31258 @FinalizeRecord
00409538 Logo12.exe System           16691 TObject.CleanupInstance
0040931d Logo12.exe System           16460 TObject.FreeInstance
004b4649 Logo12.exe madExcept        17205 InterceptClassDestroy
01b49748 Logo12.exe BSTreeSearch       197 TBSTreeSearchEdit.Destroy
004094a8 Logo12.exe System           16529 TObject.Free
0379638c Logo12.exe viewConfigGebiet    56 TFViewConfigGebiet.DoFinalizeView
0233d99c Logo12.exe BSDock             512 TBSDockPanel.LoadView
0233d512 Logo12.exe BSDock             419 TBSDockPanel.ClearView
0233d788 Logo12.exe BSDock             453 TBSDockPanel.Destroy
004094a8 Logo12.exe System           16529 TObject.Free
0233d452 Logo12.exe BSDock             389 TBSDockPanel.TdxDockPanelEx.Destroy
004094a8 Logo12.exe System           16529 TObject.Free
0233cac2 Logo12.exe BSDock             221 TBSDockManager.Clear
0233d3db Logo12.exe BSDock             372 TBSDockManager.SetLayoutSettings
02f17efb Logo12.exe BSModulEntity      505 TFBSModulEntity.ConfigurationLoadExecute
02f1d5b1 Logo12.exe BSModulEntity     1283 TFBSModulEntity.UpdateSettingsMenu$73$ActRec.$2$Body
01b05f11 Logo12.exe BSActnList         653 TBSAction.Execute
005443d3 Logo12.exe System.Classes   16594 TBasicActionLink.Execute
01aa5abb Logo12.exe BSRibbon           705 TBSBarLargeButton.OnClickButton
01858cef Logo12.exe dxBar            26075 TdxBarItem.DoClick
01aa5267 Logo12.exe BSRibbon           564 TBSBarButton.DoClick
01858c7b Logo12.exe dxBar            26065 TdxBarItem.DirectClick
01888af5 Logo12.exe dxBar            44805 TdxBarItemControl.ControlUnclick
0188d5e4 Logo12.exe dxBar            46935 TdxBarButtonControl.ControlUnclick
0189daac Logo12.exe dxBar            53744 TCustomdxBarControl.DoLButtonUp
0189c06f Logo12.exe dxBar            53038 TCustomdxBarControl.WMLButtonUp
007136ee Logo12.exe Vcl.Controls      7313 TControl.WndProc
00718239 Logo12.exe Vcl.Controls     10143 TWinControl.WndProc
0189cdf0 Logo12.exe dxBar            53389 TCustomdxBarControl.WndProc
00717858 Logo12.exe Vcl.Controls      9850 TWinControl.MainWndProc
005452c4 Logo12.exe System.Classes   17187 StdWndProc
006e938f Logo12.exe Vcl.Forms        10534 TApplication.ProcessMessage
I can reproduce it, but with some problems:
- it only happens when running the app outside the IDE.
- it does not always happen when running these lines of the code.
- it doesn't happen if I start to add log messages (write a string to a text file).

So it's very hard to fix it for me, maybe somebody can give me a hint, how to isolate the problem.

cu ck
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: Access violation at @UStrClr

Post by madshi »

Is BSDock your own unit? Or is it a 3rd party component?

What does viewConfigGebiet do in linear 56? It seems to free an object there. One possible issue could that this object might already been freed before.
chkaufmann
Posts: 12
Joined: Fri Dec 11, 2009 10:57 am

Re: Access violation at @UStrClr

Post by chkaufmann »

Yes BSDock.pas is from my library.
procedure TFViewConfigGebiet.DoFinalizeView;
begin
inherited;
ESearchGebiet.Free; <<<<<<<<
ESearchGebiet := nil;
end;
ESearchGebiet is an Edit Control. Because of the error I checked, what happens if I explicitly free it instead of destruction due form destruction.

The form is freed with this code:
FView.DoFinalizeView;
FView.ViewPanel.Parent := FView;
FView.Free;
FView := nil;
I create forms and move panels from there to the main form. This works fine if I move the panel back to the original form before I destroy it. I do this in many places. Here it fails with this error, but if I add a log command to the FormDestroy event, then the error does not apear. Must be some kind of timing problem, probably with Windows messages - but I don't succeed to isolate it.

cu ck
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: Access violation at @UStrClr

Post by madshi »

I don't really have enough information to just tell you how to fix the issue. So I can only give some tips:

1) Maybe try using a thread safe counter (InterlockedIncrement/Decrement) every time you create or destroy ESearchGebiet. Do this just to check if you're freeing twice.
2) Maybe in the ESearchGebiet destructor set a flag "ImAlreadyDestroyed := true", then check if the flag is already set, as another means to detect a double free.
3) Maybe check for "If GetCurrentThreadId <> MainThreadId" in the ESearchGebiet destructur to detect a situation where a secondary thread may free ESearchGebiet, although that seems unlikely (?).
4) Maybe activate the "instantly crash on buffer overrun" feature, as as test. It should also produce a crash if you try to free something twice.

These are just checks to see if you free it twice. It's just a guess on my part that this is causing the issue. It could be something else.
Post Reply