Recent

Author Topic: Sigsegv when closing application while balloon hint (TTrayIcon) is still visible  (Read 8290 times)

exodusd

  • New member
  • *
  • Posts: 9
Hello,

i'm getting a SIGSEGV when closing my application while the balloon hint of a TTrayIcon is still showing. This seems to happen only when i compile in debug mode (on Windows 8.1 64bit). The debugger jumps into assembly code when i halt execution on that error, apparently stuck in the following function:
LCLINTF_GETWINDOWLONG$LONGWORD$LONGINT$$LONGINT (34)

Has anybody else stumbled over this? Any idea how to fix it, or should i just ignore it? It doesn't seem to happen in the version compiled for release, but i'm not sure if there is something wrong with the ballon hint notifier window still showing and its timer still running when the application closes. I already took a look at TTrayIcon and TCustomTrayIcon, but the variables that control the balloon hint (FNotifier and FTimer) are both private (not protected), so i can't just write a derived class and try to manually hide the notifier.

I'm using the official lazarus version 1.2.6 for windows:
Lazarus 1.2.6, FPC 2.6.4, SVN-Revision 46529, i386-win32-win32/win64.

I've attached a small test application with a button to show the ballon hint (which will stay visible for 10 seconds to give enough time to click the 'Exit' button and close the application ;-) ).

Cheers,
  Robert

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Please test with Lazarus Release Candidate 2 of 1.4 : http://forum.lazarus.freepascal.org/index.php/topic,27567.0.html

Or with Lazarus trunk version. I recall there were fixes for timers and their handling during application termination phase.

exodusd

  • New member
  • *
  • Posts: 9
I just tested with the Win32 version of Lazarus 1.4 RC 2 (FPC 2.6.4, SVN-Revision: 48058).
The error also occurs in this version (when compiling a debug version of the test application).

I'll try to test with an svn trunk version, but i haven't compiled lazarus or freepascal from svn yet, so i'm not sure how quick i can report back. ;-)

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
I don't know what produces the error but this will help you to proceed
Code: [Select]
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: boolean);
begin
  TrayIcon1.Hide;
end;
test it with your example project on win7/64 bit and solves the issue
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

exodusd

  • New member
  • *
  • Posts: 9
Thanks, that got rid of problem. In my real application I was using a TDataModule instead of a form, but explicitly hiding the tray icon in the DataModuleDestroy event also works.

By the way, i was able to reproduce the problem with lazarus from svn trunk. This resulted in slightly better debug info: the SIGSEGV occurs in include\winapi.inc on line 541, that's the GetWindowLong call on the widget set:

Code: [Select]
function GetWindowLong(Handle : hwnd; int : Integer): PtrInt;
begin
  Result := WidgetSet.GetWindowLong(Handle, int);
end;

There's no call stack, though, so i can't say where this is called from when the application exits...

Maybe that helps you in tracking down the source of the problem. I can live with the solution of hiding the tray icon, though.

Cheers,
  Robert
« Last Edit: March 27, 2015, 09:22:05 pm by exodusd »

zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Widgetset object is destroyed ? hmmmm if it's so than TrayIcon is doing someting wrong afer Application.Terminate.

exodusd

  • New member
  • *
  • Posts: 9
Well, i don't really know any LCL internals, so i can only guess. It seems to me that the notifier and timer of the tray icon that display the balloon hint are still "active". The problem only seems to occur when the application terminates while the balloon hint is still visible (or beginning to fade).

zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Please open an issue about it, it's possible that it can be fixed before 1.4 is out. Also, do not forget to attach example project.

exodusd

  • New member
  • *
  • Posts: 9
Done: http://bugs.freepascal.org/view.php?id=27743
I'm not sure if "LCL" is the correct category, but i guess someone will correct me if it isn't. ;-)

Cheers - and thanks for taking the time to look into this,
  Robert

zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
I cannot reproduce your problem, with your example project.

exodusd

  • New member
  • *
  • Posts: 9
Hm, this is weird. I just checked again in both 1.4 RC2 and 1.5 (svn).

Just to be sure: Have you switched to debug mode in the project settings when compiling? If i'm not mistaken i noticed that the default seems to be "default" mode in the published project. I run the project in the Lazarus debugger (by hitting F9). I click "Show Balloon Hint" and then (when the hint is shown) on "Exit". I then end up with Lazarus telling me that an "External: SIGSEGV" exception happened.

I'm running Windows 8.1 64-bit - I currently don't have another windows version to test against...

zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Hm, this is weird. I just checked again in both 1.4 RC2 and 1.5 (svn).

Just to be sure: Have you switched to debug mode in the project settings when compiling? If i'm not mistaken i noticed that the default seems to be "default" mode in the published project. I run the project in the Lazarus debugger (by hitting F9). I click "Show Balloon Hint" and then (when the hint is shown) on "Exit". I then end up with Lazarus telling me that an "External: SIGSEGV" exception happened.

I'm running Windows 8.1 64-bit - I currently don't have another windows version to test against...

No, I did not test it via debugger. Project is compiled with debug , but executed outside IDE.

rvk

  • Hero Member
  • *****
  • Posts: 6111
I can confirm.
Windows 7 ultimate, Trunk Lazarus/FPC
Lazarus 1.5 r47609 FPC 3.1.1 i386-win32-win32/win64

You do need to set the debugging from "Default" to "Debug" to get this error.

I also found out, when in "Debug", you just have to uncheck the "Use heaptrc unit" to make the error go away, so you might want to look in the direction of the heaptrace-unit for the error.

rvk

  • Hero Member
  • *****
  • Posts: 6111
As far as I can see at this point:

The problem is with a call to TrayWndProc (background Windows queue processing procedure of TrayIcon) after the Close-command.

Set a breakpoint in lcl/interfaces/win32/win32trayicon.inc
on the line with GetWindowLong and you see it is called with lParam = 0x403 (or 1027). Anybody know what 0x403 is for.

But at that time the Window-handle is probably already invalid.

You could change it in only calling GetWindowLong when lParam is one of the WM_ below it. There is no need for filling the vwsTrayIcon-variable if the statements below are not using it.

Code: [Select]
function TrayWndProc(Handle: HWND; iMsg: UINT; WParam_: WPARAM; LParam_:LPARAM):LRESULT; stdcall;
var
  pt: TPoint;
  vwsTrayIcon: TCustomTrayIcon;
begin
  if iMsg = WM_USER + uIDTrayIcon then
  begin
    vwsTrayIcon := TCustomTrayIcon(PtrUInt(GetWindowLong(Handle, GWL_USERDATA)));
    case LParam_ of
      WM_RBUTTONUP:

For instance... doing this solves it:
Code: [Select]
if LParam_ = WM_PSD_MARGINRECT then exit; // we're not handling this case.
vwsTrayIcon := TCustomTrayIcon(PtrUInt(GetWindowLong(Handle, GWL_USERDATA)));
But I'm sure that's not a good solution.
You need to fix the reason this procedure is called so late with WM_PSD_MARGINRECT. (or check for validity of the Windows-handle before calling GetWindowLong in that line)
« Last Edit: March 29, 2015, 07:03:40 pm by rvk »

zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
I'll test on real windows tomorrow @work, so then I'll know more. As you explained it's dangling handle pointer.

 

TinyPortal © 2005-2018