View Issue Details

IDProjectCategoryView StatusLast Update
0033809LazarusLCLpublic2019-06-09 10:32
ReportercircularAssigned ToJuha Manninen 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version1.8.6Product Build 
Target VersionFixed in Version 
Summary0033809: calling TextRect with Font.Name = '' raises SIGSEGV
DescriptionUsing Font.Name and then calling TextRect raises SIGSEGV in NeedOffsetCalc function.

#0 NEEDOFFSETCALC(0x7fffffffd130) at gtk2/gtk2winapi.inc:2571
0000001 DRAWLINERAW(0x7fffffffd130, 0x7728f8 'Hello world', 11, 0) at gtk2/gtk2winapi.inc:2602
0000002 DRAWTEXT(0x7ffff7f80230, 140737201115200, 0x7728f8 'Hello world', 11, {LEFT = 0, TOP = 0, RIGHT = 320, BOTTOM = 240, TOPLEFT = {X = 0, Y = 0}, BOTTOMRIGHT = {X = 320, Y = 240}, VECTOR = {0, 0, 320, 240}}, 2352) at gtk2/gtk2winapi.inc:2697
0000003 DRAWTEXT(140737201115200, 0x7728f8 'Hello world', 11, {LEFT = 0, TOP = 0, RIGHT = 320, BOTTOM = 240, TOPLEFT = {X = 0, Y = 0}, BOTTOMRIGHT = {X = 320, Y = 240}, VECTOR = {0, 0, 320, 240}}, 2352) at include/winapi.inc:215
0000004 TEXTRECT(0x7fffeef29a40, {LEFT = 0, TOP = 0, RIGHT = 320, BOTTOM = 240, TOPLEFT = {X = 0, Y = 0}, BOTTOMRIGHT = {X = 320, Y = 240}, VECTOR = {0, 0, 320, 240}}, 0, 0, 0x7728f8 'Hello world', {ALIGNMENT = TALEFTJUSTIFY, LAYOUT = TLTOP, SINGLELINE = true, CLIPPING = true, EXPANDTABS = false, SHOWPREFIX = false, WORDBREAK = true, OPAQUE = false, SYSTEMFONT = false, RIGHTTOLEFT = false, ENDELLIPSIS = false}) at include/canvas.inc:1331
0000005 TEXTRECT(0x7fffeef29a40, {LEFT = 0, TOP = 0, RIGHT = 320, BOTTOM = 240, TOPLEFT = {X = 0, Y = 0}, BOTTOMRIGHT = {X = 320, Y = 240}, VECTOR = {0, 0, 320, 240}}, 0, 0, 0x7728f8 'Hello world') at include/canvas.inc:1212
Steps To Reproducecreate an application and in the form paint event:

procedure TForm1.FormPaint(Sender: TObject);
begin
  Canvas.Font.Name := '';
  Canvas.Brush.Style := bsClear;
  Canvas.TextRect(rect(0,0,ClientWidth,ClientHeight),0,0,'Hello world');
end;
Additional InformationProblem is that NeedOffsetCalc uses CurrentFont property of TGtkDeviceContext which is not initialized. Using GetFont instead seems to solve the problem.
TagsNo tags attached.
Fixed in Revisionr61344
LazTarget-
WidgetsetGTK 2
Attached Files
  • 0001-LCL-Use-font-name-default-if-it-was-empty.patch (719 bytes)
    From 619fe0233f816ba7f29d7b8c78b7c80bc32b5f03 Mon Sep 17 00:00:00 2001
    From: juha <juha.manninen62@gmail.com>
    Date: Fri, 8 Jun 2018 13:23:04 +0300
    Subject: [PATCH] LCL: Use font name 'default' if it was empty.
    
    ---
     lcl/include/canvas.inc | 4 ++++
     1 file changed, 4 insertions(+)
    
    diff --git a/lcl/include/canvas.inc b/lcl/include/canvas.inc
    index 5abe1c597..0439a2333 100644
    --- a/lcl/include/canvas.inc
    +++ b/lcl/include/canvas.inc
    @@ -1241,6 +1241,10 @@ var
       
     begin
       //debugln(['TCanvas.TextRect ',DbgSName(Self),' Text="',Text,'" ',dbgs(ARect),' X=',X,',Y=',Y]);
    +
    +  if Font.Name = '' then      // Empty name is allowed in Delphi.
    +    Font.Name := 'default';
    +
       Changing;
       
       Options := 0;
    -- 
    2.17.1
    
    

Activities

Zeljan Rikalo

2018-05-31 14:28

developer   ~0108614

Why Font.Name := ''; ? Use 'default' if you don't know font name.

Bart Broersma

2018-05-31 15:33

developer   ~0108620

D7 allows this (it does not crash).
So, whilst it may look rather insane, it is an incompatibility with Delphi.

Zeljan Rikalo

2018-06-01 10:08

developer   ~0108632

So we should patch LCL in that case

circular

2018-06-01 16:38

developer   ~0108634

I agree it is not a valid font name. But crashing is not great and it is not obvious why it crashes for a regular user. If the LCL does not accept it, then one might raise an exception.

Zeljan Rikalo

2018-06-01 16:39

developer   ~0108635

Or exception or set "default" as font name

circular

2018-06-03 22:06

developer   ~0108670

Yep.

Juha Manninen

2018-06-08 12:27

developer  

0001-LCL-Use-font-name-default-if-it-was-empty.patch (719 bytes)
From 619fe0233f816ba7f29d7b8c78b7c80bc32b5f03 Mon Sep 17 00:00:00 2001
From: juha <juha.manninen62@gmail.com>
Date: Fri, 8 Jun 2018 13:23:04 +0300
Subject: [PATCH] LCL: Use font name 'default' if it was empty.

---
 lcl/include/canvas.inc | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lcl/include/canvas.inc b/lcl/include/canvas.inc
index 5abe1c597..0439a2333 100644
--- a/lcl/include/canvas.inc
+++ b/lcl/include/canvas.inc
@@ -1241,6 +1241,10 @@ var
   
 begin
   //debugln(['TCanvas.TextRect ',DbgSName(Self),' Text="',Text,'" ',dbgs(ARect),' X=',X,',Y=',Y]);
+
+  if Font.Name = '' then      // Empty name is allowed in Delphi.
+    Font.Name := 'default';
+
   Changing;
   
   Options := 0;
-- 
2.17.1

Juha Manninen

2018-06-08 12:29

developer   ~0108748

Could it be as simple as the attached patch?
The font name will be "default" also after the call but it should be OK as an empty name will never be valid.

Juha Manninen

2018-06-10 20:50

developer   ~0108818

Ping all of you.

Juha Manninen

2018-09-13 12:47

developer   ~0110716

No response from anybody. :(
Unassigning myself.

circular

2019-06-07 10:35

developer   ~0116602

Sorry for the late reply. I think indeed it is as simple as what you suggest Juha. Though not having trunk I cannot test it.

Juha Manninen

2019-06-09 10:32

developer   ~0116645

Ok, I applied it. Please test with trunk.

Issue History

Date Modified Username Field Change
2018-05-31 13:26 circular New Issue
2018-05-31 14:28 Zeljan Rikalo Note Added: 0108614
2018-05-31 15:33 Bart Broersma Note Added: 0108620
2018-06-01 10:08 Zeljan Rikalo Note Added: 0108632
2018-06-01 16:38 circular Note Added: 0108634
2018-06-01 16:39 Zeljan Rikalo Note Added: 0108635
2018-06-03 22:06 circular Note Added: 0108670
2018-06-08 12:27 Juha Manninen File Added: 0001-LCL-Use-font-name-default-if-it-was-empty.patch
2018-06-08 12:29 Juha Manninen Note Added: 0108748
2018-06-10 20:49 Juha Manninen Assigned To => Juha Manninen
2018-06-10 20:49 Juha Manninen Status new => assigned
2018-06-10 20:50 Juha Manninen Note Added: 0108818
2018-06-10 20:50 Juha Manninen Status assigned => feedback
2018-09-13 12:45 Juha Manninen Assigned To Juha Manninen => circular
2018-09-13 12:45 Juha Manninen Status feedback => assigned
2018-09-13 12:47 Juha Manninen Note Added: 0110716
2018-09-13 12:47 Juha Manninen Status assigned => feedback
2019-06-07 10:35 circular Note Added: 0116602
2019-06-07 10:35 circular Assigned To circular => Juha Manninen
2019-06-09 10:32 Juha Manninen Status feedback => resolved
2019-06-09 10:32 Juha Manninen Resolution open => fixed
2019-06-09 10:32 Juha Manninen Fixed in Revision => r61344
2019-06-09 10:32 Juha Manninen Widgetset GTK 2 => GTK 2
2019-06-09 10:32 Juha Manninen Note Added: 0116645