Lazarus

Programming => Widgetset => CustomDrawn => Topic started by: lagprogramming on April 02, 2023, 02:43:54 pm

Title: [SOLVED] Patch for fixing a bug at TCDWidgetSet.SaveDC
Post by: lagprogramming on April 02, 2023, 02:43:54 pm
According to the comments found all over the interfaces, the function should return the index assigned to OR 0 if DC is not valid. The problem is that the original code returns the index of TLazCanvas.SaveState, which can be zero. This makes a valid TLazCanvas.SaveState zero index to be interpreted as if DC is not valid.
The patch mimics the solution found in function TCocoaContext.SaveDC: Integer; The function result is the index in the list + 1. This means that the first SaveDC will be one, not zero.



Code: Pascal  [Select][+][-]
  1. diff --git a/lcl/interfaces/customdrawn/customdrawnwinapi.inc b/lcl/interfaces/customdrawn/customdrawnwinapi.inc
  2. index 0a12ac2d82..dbdcb15667 100644
  3. --- a/lcl/interfaces/customdrawn/customdrawnwinapi.inc
  4. +++ b/lcl/interfaces/customdrawn/customdrawnwinapi.inc
  5. @@ -5033,10 +5033,13 @@ begin
  6.    {$ifdef VerboseQTWinAPI}
  7.    WriteLn('Trace:> [WinAPI RestoreDC] DC=', dbghex(DC),' SavedDC=',SavedDC);
  8.    {$Endif}
  9. -  Result := False;
  10. -  if not IsValidDC(DC) then Exit;
  11. +  if (SavedDC=0) or (not IsValidDC(DC)) then Exit(False);
  12. +
  13. +  if SavedDC>0 then
  14. +    LazDC.RestoreState(SavedDC-1)
  15. +  else
  16. +    LazDC.RestoreState(SavedDC);
  17.  
  18. -  LazDC.RestoreState(SavedDC);
  19.    Result := True;
  20.    {$ifdef VerboseQTWinAPI}
  21.    WriteLn('Trace:< [WinAPI RestoreDC]');
  22. @@ -5079,7 +5082,7 @@ begin
  23.      exit;
  24.    end;
  25.  
  26. -  Result := LazDC.SaveState();
  27. +  Result := LazDC.SaveState()+1;
  28.  
  29.    {$ifdef VerboseQTWinAPI}
  30.    WriteLn('Trace:< [WinAPI SaveDC] result=', Result);
Title: Re: Patch for fixing a bug at TCDWidgetSet.SaveDC
Post by: Bart on April 02, 2023, 03:52:50 pm
Please post patches in the appropriate place: the bugtracker.
Also notice that the current state of CustomDrawn widgetset makes it impossible to test (at least on Windows) the changes you made.

Bart
Title: Re: Patch for fixing a bug at TCDWidgetSet.SaveDC
Post by: wp on April 02, 2023, 04:38:38 pm
I absolutely agree with Bart: Please post the bug to the bug tracker so that it is well-documented and some knowledgable developer can take care of it. I will not apply this one because it is not self-evident (like the others) and we have no means to test it.
Title: Re: Patch for fixing a bug at TCDWidgetSet.SaveDC
Post by: lagprogramming on April 04, 2023, 01:08:49 pm
I don't have a problem with the fact that a patch presented by me is not included in the official source code.
Also, I find hard to believe that somebody would continue the development of customdrawn without reading the forum posts in the customdrawn subcategory. Or the customdrawn mailing list.
Title: Re: Patch for fixing a bug at TCDWidgetSet.SaveDC
Post by: PascalDragon on April 05, 2023, 09:15:17 pm
Also, I find hard to believe that somebody would continue the development of customdrawn without reading the forum posts in the customdrawn subcategory. Or the customdrawn mailing list.

There are people that don't frequent the forum. This includes even some core developers. And not many people are subscribed to the customdrown mailing list (I hadn't even remembered that there is one).
Title: Re: Patch for fixing a bug at TCDWidgetSet.SaveDC
Post by: AlexTP on April 11, 2023, 01:49:11 pm
Posted to bugtracker:
https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/40205
TinyPortal © 2005-2018