Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-08

GetParent returning Self

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin Grajcar

In /usr/share/lazarus/1.2.6/lcl/interfaces/carbon/carbonprivatewindow.inc:299 (CarbonWindow_MouseProc ) there's the following code

  while Assigned(Widget) and not Widget.IsEnabled do
  begin
    // Here we need to avoid an endless loop which might occur in case
    // GetParent returns the same widget that we passed
    lTmpWidget := TCarbonWidget(CarbonWidgetset.GetParent(HWND(Widget)));
    if lTmpWidget = Widget then Break;
    Widget := lTmpWidget;
  end;

In our application, it indeed happens somehow, that the condition lTmpWidget = Widget holds. This test helps to break the infinite cycle, but

function TCarbonWidgetSet.GetParent(Handle: HWND): HWND;

in /usr/share/lazarus/1.2.6/lcl/interfaces/carbon/carbonwinapi.inc:1794 gets also used from elsewhere, namely
from /usr/share/lazarus/1.2.6/lcl/include/winapi.inc:432

function GetParent(Handle : HWND): HWND;

which gets used from C code handling the event loop. It looks like there's a similar problem happening there, an endless loop keeping the CPU busy and the application dead.

As a workaround, I appended

if Result = Handle then Result := 0;

to TCarbonWidgetSet.GetParent but this feels hacky.

My questions are:

1. Am I right assuming that a windows having itself as parent is always wrong?
2. Is there a simple way how to find where this happens? I know it's not in in TCarbonWidgetSet.SetParent.
3. Is my workaround correct?

Regards, Martin.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150801/1dd40fb8/attachment.html>

Reply by email