TMSFNCTreeview

Using the TreeView on macOS I get the following messages in the PAServer window:

...Nov  7 15:19:04  Project1[3473] <Error>: CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.Nov  7 15:19:04  Project1[3473] <Error>: CGContextRestoreGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.Nov  7 15:19:04  Project1[3473] <Error>: CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.Nov  7 15:19:04  Project1[3473] <Error>: CGContextRestoreGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

<o:p></o:p>

Place the TreeView to an TForm, add a TButton with the following code in the OnClick() event:

procedure TForm1.Button1Click(Sender: TObject);var  i : Integer;begin  TreeView.BeginUpdate;  for i := 1 to 1000 do     TreeView.AddNode(nil).Text[0] := 'Test with <b>bold</b><br/>New Line';  TreeView.EndUpdate;end;

run it on macOS, click on the Button and scroll to the end.
Click at some lines.


Hi, 


We are not able to reproduce this issue here, with the above sample code.
Are you setting additional properties in the object inspector, or is this reproducible with a default TTMSFNCTreeView on the form? Which RAD Studio and macOS version are you using specifically?
Yes just drop the TreeView and add this code.

I'm using Delphi 10.1 Berlin Update 2. Version 24.0.25048.9432. 
On Mac side: macOS 10.11.6

We have used this code and tested this in Tokyo, where it is no longer reproducible. I suggest to test this in Tokyo or upgrade where this issue no longer occurs.

Quick check on Berlin. Here the callstack:

FMX.Canvas.Mac.TQuartzCanvasSaveState.Assign($79C65F0)
:004479cb TQuartzCanvasSaveState.Assign + $47
FMX.TMSFNCGraphics.General.TTMSFNCGraphicsContextGeneral.SaveState($7CC0B70)
FMX.TMSFNCGraphics.TTMSFNCGraphics.SaveState(True)
FMX.TMSFNCGraphics.TTMSFNCGraphics.InternalDrawText((22,5, 265,5, 189,33332824707, 286,5, ((22,5, 265,5), 22,5, 265,5), ((189,33332824707, 286,5), 189,33332824707, 286,5)),'Test with <b>bold</b><br/>New Line','','','',False,gtaLeading,gtaCenter,gttNone,0,-1,-1,True,True,74,267)
FMX.TMSFNCGraphics.TTMSFNCGraphics.DrawText((22,5, 265,5, 189,33332824707, 286,5, ((22,5, 265,5), 22,5, 265,5), ((189,33332824707, 286,5), 189,33332824707, 286,5)),'Test with <b>bold</b><br/>New Line','','','',False,gtaLeading,gtaCenter,gttNone,0,-1,-1,True,True,74,267)
FMX.TMSFNCGraphics.TTMSFNCGraphics.DrawText((22,5, 265,5, 189,33332824707, 286,5, ((22,5, 265,5), 22,5, 265,5), ((189,33332824707, 286,5), 189,33332824707, 286,5)),'Test with <b>bold</b><br/>New Line',False,gtaLeading,gtaCenter,gttNone,0,-1,-1,True,True,74,267)
FMX.TMSFNCCustomTreeView.TTMSFNCCustomTreeView.XYToNodeAnchor($7D1A4E0,74,267)
FMX.TMSFNCCustomTreeView.TTMSFNCCustomTreeView.HandleMouseDown(mbLeft,[ssLeft],74,267)
...

The Delphi code is the same in Tokio. No check to the context:


procedure TQuartzCanvasSaveState.Assign(Source: TPersistent);
begin
  inherited Assign(Source);
  if Source is TCanvasQuartz then
    CGContextSaveGState(TCanvasQuartz(Source).Context);
end;

Hi, 


Looking at the code in TQuartzCanvasSaveState it seems to be a crucial mistake in not checking if the Context is still assigned when assigning a source. This should at the very least be handled by the FMX framework. We'll investigate if we can find a workaround, after we can determine how to reproduce the error.