Sign in Join

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

Mailing lists / lazarus / 2008-06

Carbon: GetTextExtentPoint and Access Violation

6 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

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

Bent Normann Olsen

Hi,

At certain points our application crashes, like when a control is about to show a hint, and then throws an exception 'External: EXC_BAD_ACCESS', and breaks at line 1725 in carbonwinapi.inc: "if not CheckDC(DC, 'GetTextExtentPoint') then Exit;"

I traced the exact crash point to line 1582 in control.inc: "Dispatch(TheMessage)".

The GetTextExtentPoint is called 6 times currently with the same string and no problems, and the Dispatch is called twice after the 6th time with no problems, but crashes at the 3rd call to Dispatch.

The TheMessage has the following parameters:

{MSG=66592, WPARAM=265482992, LPARAM=0, RESULT=0, WPARAMLO=62192, WPARAMHI=4050, LPARAMLO=0, LPARAMHI=0, RESULTLO=0, RESULTHI=0}

I believe the WPARAM is the DC, but anybody know what MSG=66592 ($10420) is all about? Or have any clue of what causes the crash?

Note: If I let another control show its hint first, it doesn't crash if the control shows its hint - it only crash every time when it's the first control to show its hint.

Thanks and best regards,
Normann

Reply by email

Tom Gregorovic
to Bent Normann Olsen
Bent Normann Olsen wrote 21 lines
Hi, At certain points our application crashes, like when a control is about to show a hint, and then throws an exception 'External: EXC_BAD_ACCESS', and breaks at line 1725 in carbonwinapi.inc: "if not CheckDC(DC, 'GetTextExtentPoint') then Exit;" I traced the exact crash point to line 1582 in control.inc: "Dispatch(TheMessage)". The GetTextExtentPoint is called 6 times currently with the same string and no problems, and the Dispatch is called twice after the 6th time with no problems, but crashes at the 3rd call to Dispatch. The TheMessage has the following parameters: {MSG=66592, WPARAM=265482992, LPARAM=0, RESULT=0, WPARAMLO=62192, WPARAMHI=4050, LPARAMLO=0, LPARAMHI=0, RESULTLO=0, RESULTHI=0} I believe the WPARAM is the DC, but anybody know what MSG=66592 ($10420) is all about? Or have any clue of what causes the crash?

Message type is LM_PAINT.
Try to debug the CheckDC. Maybe the DC is not valid object.

Tom

Reply by email

Bent Normann Olsen
to Tom Gregorovic

Thanks Tom, but it called CheckDC each time with no errors, at least after my initial tests. I can't reproduce the crash on a test application, so the crash occurs on some conditions I can't recreate.

I did find out that the DC is the hints form canvas handle, and its CustomForm.PaintWindow is called, where its canvas handle is set to 0, and soon after that Dispatch(LM_PAINT msg) is called causing a crash?

The controls are ToolButtons on a ToolBar, and only one specific button (with a hint string 'User overview (CTRL+U)') causes the crash, if it's the first to show a hint. The hint form gets visible on screen before crash.

But my biggest problem is, as mentioned, that I can't reproduce the crash on a smaller test application, which could have been a big help isolating the problem.

Any clues or ideas? I'll try to come up with some ways to locate the problem more precisely.

Normann

Earlier message 15 lines
-----Original Message----- From: [mailto:] On Behalf Of Tom Gregorovic Sent: 16. juni 2008 11:36 To: General mailing list Subject: Re: [Lazarus] Carbon: GetTextExtentPoint and Access Violation On Mon, Jun 16, 2008 at 10:53 AM, Bent Normann Olsen wrote: [snip] Message type is LM_PAINT. Try to debug the CheckDC. Maybe the DC is not valid object. Tom

Reply by email

Bent Normann Olsen
to Bent Normann Olsen

Hi again,

I tried to make a simple test by reading different components canvas handles, like:

  Caption := IntToStr(ToolButton1.Canvas.Handle);
  Caption := Caption+' '+ IntToStr(ToolBar1.Canvas.Handle);
  Caption := Caption+' '+ IntToStr(Panel3.Canvas.Handle);
  Caption := Caption+' '+ IntToStr(Panel2.Canvas.Handle);
  Caption := Caption+' '+ IntToStr(Panel1.Canvas.Handle);
  Caption := Caption+' '+ IntToStr(Form1.Canvas.Handle);

They all return the same handle (one component is parent for the next component), but more interestingly the test crashes on the main application, and not on a isolated test application. And it only crashes if I read 6 handles, not 5 or less - strange.

And also I tried different compiler options, and I that found if I check "Use Heaptrc Unit (-gh)" the displaying of hint don't crash no more, neither does the above test. But the application crash on exit.

Could this be a problem with memories on Carbon for larger applications with many components? I tried to increase "Heap Size" with no luck.

TIA,
Normann

Earlier message 8 lines
-----Original Message----- From: [mailto:] On Behalf Of Bent Normann Olsen Sent: 16. juni 2008 14:10 To: 'General mailing list' Subject: Re: [Lazarus] Carbon: GetTextExtentPoint and Access Violation [snip]

Reply by email

Tom Gregorovic
to Bent Normann Olsen
Bent Normann Olsen wrote 16 lines
Hi again, I tried to make a simple test by reading different components canvas handles, like: Caption := IntToStr(ToolButton1.Canvas.Handle); Caption := Caption+' '+ IntToStr(ToolBar1.Canvas.Handle); Caption := Caption+' '+ IntToStr(Panel3.Canvas.Handle); Caption := Caption+' '+ IntToStr(Panel2.Canvas.Handle); Caption := Caption+' '+ IntToStr(Panel1.Canvas.Handle); Caption := Caption+' '+ IntToStr(Form1.Canvas.Handle); They all return the same handle (one component is parent for the next component), but more interestingly the test crashes on the main application, and not on a isolated test application. And it only crashes if I read 6 handles, not 5 or less - strange.

The handles are the same, because they point to fake object DefaultContext. The reason is that you can't paint on Carbon controls outside paint event. DefaultContext is a bitmap canvas. Can you debug the exact line which causes the crash?

Show quoted text 7 lines
And also I tried different compiler options, and I that found if I check "Use Heaptrc Unit (-gh)" the displaying of hint don't crash no more, neither does the above test. But the application crash on exit. Could this be a problem with memories on Carbon for larger applications with many components? I tried to increase "Heap Size" with no luck.

It sounds really strange, what FPC and platform (intel or ppc) do you use?

Tom

Reply by email

Bent Normann Olsen
to Tom Gregorovic
Show quoted text 6 lines
-----Original Message----- From: [mailto:lazarus- ] On Behalf Of Tom Gregorovic Sent: 17. juni 2008 10:38 To: General mailing list Subject: Re: [Lazarus] Carbon: GetTextExtentPoint and Access Violation

[snip]

Can you debug the exact line which causes the crash?

It crashes when I hit F7 in file "control.inc" at line 1582 with code "Dispatch(TheMessage)".

TheMessage contains a LM_PAINT message.

It sounds really strange, what FPC and platform (intel or ppc) do you use?

I am using FPC v2.2.0 [2008/05/29] for i386 with Mac OS X v10.4.11.

Normann

Reply by email