View Issue Details

IDProjectCategoryView StatusLast Update
0035646LazarusLCLpublic2019-06-01 12:22
ReporterLuca OlivettiAssigned ToZeljan Rikalo 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version2.0.2Product Build 
Target VersionFixed in Version 
Summary0035646: TPageControl: setting Images to nil produces a sigsev [PATCH]
DescriptionIf the images property of a tpagecontrol is assigned, setting it to nil produces a sigsev.
In my application this happens every time the form is destroyed, in the example project this doesn't happen, so I added a button to set images to nil.
Steps To ReproduceCompile and run the attached project. Click on the button. See the SIGSEV.
Additional InformationChanging the Images property triggers the DoImageListChange method of TCustomTabControl (in customnotebook.inc).
With lazarus 1.8.x this was no problem, but now this method tries to access Images which is nil at this point, thus causing a sigsev.
The patch seems to fix the problem.
TagsNo tags attached.
Fixed in Revision61308
LazTarget-
Widgetset
Attached Files
  • project1.zip (128,256 bytes)
  • customnotebook.patch (563 bytes)
    Index: lcl/include/customnotebook.inc
    ===================================================================
    --- lcl/include/customnotebook.inc	(revision 61054)
    +++ lcl/include/customnotebook.inc	(working copy)
    @@ -1220,7 +1220,7 @@
     
     procedure TCustomTabControl.DoImageListChange(Sender: TObject);
     begin
    -  if HandleAllocated then
    +  if HandleAllocated and Assigned(Images) then
         TWSCustomTabControlClass(WidgetSetClass).SetImageList(Self, Images.ResolutionForPPI[ImagesWidth, Font.PixelsPerInch, 1].Resolution); // to-do: support scaling factor
     end;
     
    
    customnotebook.patch (563 bytes)
  • customnotebook-2.patch (876 bytes)
    Index: lcl/include/customnotebook.inc
    ===================================================================
    --- lcl/include/customnotebook.inc	(revision 61054)
    +++ lcl/include/customnotebook.inc	(working copy)
    @@ -1221,7 +1221,12 @@
     procedure TCustomTabControl.DoImageListChange(Sender: TObject);
     begin
       if HandleAllocated then
    -    TWSCustomTabControlClass(WidgetSetClass).SetImageList(Self, Images.ResolutionForPPI[ImagesWidth, Font.PixelsPerInch, 1].Resolution); // to-do: support scaling factor
    +  begin
    +    if Assigned(Images) then
    +      TWSCustomTabControlClass(WidgetSetClass).SetImageList(Self, Images.ResolutionForPPI[ImagesWidth, Font.PixelsPerInch, 1].Resolution) // to-do: support scaling factor
    +    else
    +      TWSCustomTabControlClass(WidgetSetClass).SetImageList(Self, nil);
    +  end;
     end;
     
     procedure TCustomTabControl.DoImageListDestroyResolutionHandle(
    

Activities

Luca Olivetti

2019-05-29 15:24

reporter  

project1.zip (128,256 bytes)
customnotebook.patch (563 bytes)
Index: lcl/include/customnotebook.inc
===================================================================
--- lcl/include/customnotebook.inc	(revision 61054)
+++ lcl/include/customnotebook.inc	(working copy)
@@ -1220,7 +1220,7 @@
 
 procedure TCustomTabControl.DoImageListChange(Sender: TObject);
 begin
-  if HandleAllocated then
+  if HandleAllocated and Assigned(Images) then
     TWSCustomTabControlClass(WidgetSetClass).SetImageList(Self, Images.ResolutionForPPI[ImagesWidth, Font.PixelsPerInch, 1].Resolution); // to-do: support scaling factor
 end;
 
customnotebook.patch (563 bytes)

Zeljan Rikalo

2019-05-31 19:04

developer   ~0116483

hmmm...in that case we cannot clear images from WS control. IMO your patch is wrong, you should pass nil to WS if images = nil and that's correct.
WS should clear images if nil images are passed.

Luca Olivetti

2019-05-31 20:50

reporter   ~0116491

That's what 1.8.4 did:

procedure TCustomTabControl.DoImageListChange(Sender: TObject);
begin
  if HandleAllocated then
    TWSCustomTabControlClass(WidgetSetClass).SetImageList(Self, Images);
end;

but in 2.0.2 SetImageList uses the resolution as the parameter?!?!?!
Maybe that's the real problem and it should do the same as it did in 1.8.4

Luca Olivetti

2019-05-31 20:55

reporter   ~0116493

what about (untested):

if HandleAllocated then
begin
    if Assigned(Images) then
      .....
    else
       TWSCustomTabControlClass(WidgetSetClass).SetImageList(Self, nil);
end;

Luca Olivetti

2019-05-31 21:00

reporter   ~0116494

New patch, tested under Linux

customnotebook-2.patch (876 bytes)
Index: lcl/include/customnotebook.inc
===================================================================
--- lcl/include/customnotebook.inc	(revision 61054)
+++ lcl/include/customnotebook.inc	(working copy)
@@ -1221,7 +1221,12 @@
 procedure TCustomTabControl.DoImageListChange(Sender: TObject);
 begin
   if HandleAllocated then
-    TWSCustomTabControlClass(WidgetSetClass).SetImageList(Self, Images.ResolutionForPPI[ImagesWidth, Font.PixelsPerInch, 1].Resolution); // to-do: support scaling factor
+  begin
+    if Assigned(Images) then
+      TWSCustomTabControlClass(WidgetSetClass).SetImageList(Self, Images.ResolutionForPPI[ImagesWidth, Font.PixelsPerInch, 1].Resolution) // to-do: support scaling factor
+    else
+      TWSCustomTabControlClass(WidgetSetClass).SetImageList(Self, nil);
+  end;
 end;
 
 procedure TCustomTabControl.DoImageListDestroyResolutionHandle(

Zeljan Rikalo

2019-05-31 22:43

developer   ~0116500

Second one looks correct

Zeljan Rikalo

2019-06-01 09:11

developer   ~0116509

Thanks for the patch. Please test and close if ok.

Luca Olivetti

2019-06-01 12:22

reporter   ~0116514

Thank you. Please don't forget to merge it also to the fixes_2_0 branch.

Issue History

Date Modified Username Field Change
2019-05-29 15:24 Luca Olivetti New Issue
2019-05-29 15:24 Luca Olivetti File Added: project1.zip
2019-05-29 15:24 Luca Olivetti File Added: customnotebook.patch
2019-05-31 19:04 Zeljan Rikalo Note Added: 0116483
2019-05-31 20:50 Luca Olivetti Note Added: 0116491
2019-05-31 20:55 Luca Olivetti Note Added: 0116493
2019-05-31 21:00 Luca Olivetti File Added: customnotebook-2.patch
2019-05-31 21:00 Luca Olivetti Note Added: 0116494
2019-05-31 22:43 Zeljan Rikalo Note Added: 0116500
2019-06-01 09:11 Zeljan Rikalo Assigned To => Zeljan Rikalo
2019-06-01 09:11 Zeljan Rikalo Status new => assigned
2019-06-01 09:11 Zeljan Rikalo Status assigned => resolved
2019-06-01 09:11 Zeljan Rikalo Resolution open => fixed
2019-06-01 09:11 Zeljan Rikalo Fixed in Revision => 61308
2019-06-01 09:11 Zeljan Rikalo LazTarget => -
2019-06-01 09:11 Zeljan Rikalo Note Added: 0116509
2019-06-01 12:22 Luca Olivetti Status resolved => closed
2019-06-01 12:22 Luca Olivetti Note Added: 0116514