Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Finalization crash in Unit ElHook.pas

This is very similar to the recent "Errors in Unit LMDHookComponent" issue.

It crashes in finalization as HookList has some TCtlHooks referencing controls that are deleted.

In TElHook.SetActive(false), the FCtlHooks.Remove fix method from LMDHookComponent doesn't work because ElHook.TCtlHook.HookWndProc may be on the call stack, so you don't want to free its instance data too early. Instead you could set CH.FControl to nil (as below), which doesn't crash but the list will grow until the program exits and finalization runs.


ElHook.pas, SetActive:

if HookList <> nil then
begin
CH := HookList.GetCtlHook(FControl);
if CH <> nil then
begin
CH.RemoveHook(Self);
if CH.FHooks.Count = 0 then
begin
// HookList.FCtlHooks.Remove(CH); //crashes further down call stack
CH.FControl := nil; // clear the control, list grows forever?
end
end;
end;

Comments

Sign In or Register to comment.