Recent

Author Topic: [SOLVED] Patch for fixing a bug at TCDWidgetSet.SaveDC  (Read 1840 times)

lagprogramming

  • Sr. Member
  • ****
  • Posts: 405
[SOLVED] Patch for fixing a bug at TCDWidgetSet.SaveDC
« 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);
« Last Edit: April 15, 2023, 10:46:05 am by lagprogramming »

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Patch for fixing a bug at TCDWidgetSet.SaveDC
« Reply #1 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

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Patch for fixing a bug at TCDWidgetSet.SaveDC
« Reply #2 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.

lagprogramming

  • Sr. Member
  • ****
  • Posts: 405
Re: Patch for fixing a bug at TCDWidgetSet.SaveDC
« Reply #3 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.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5448
  • Compiler Developer
Re: Patch for fixing a bug at TCDWidgetSet.SaveDC
« Reply #4 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).

AlexTP

  • Hero Member
  • *****
  • Posts: 2386
    • UVviewsoft

 

TinyPortal © 2005-2018