TCastleControl flashing in delphi vcl form?

Someone has hired me to make a 3d view in their simple traffic simulator. Their project is in Delphi using VCL. It is a very simple layout with a heading panel a footer panel and a paintbox which I would replace with CGE. For now I have just placed a TCastleControl in the footer panel. No other mods, so just should be small black rectangle… which it is when I run except it flashes a lot, ie disappears to the background. His program is very simple, painting to that paintbox on a timer. It isn’t doing a global repaint or anything like that. I have it loading the 3d scene from the vcl demo, but removing all the creatures and buildings so it is just plane and light. The program is sitting idle, but still the control flashes. The CastleControl is down in the lower left…

Hm, I don’t know but the first thing I would test is: whether the CGE example using TCastleControl on VCL is flashing for you. It is in examples/delphi/vcl, just open it with Delphi and test.

If examples/delphi/vcl is also flashing for you – then we have a CGE bug we want to fix :slight_smile: Please then report your system / GPU details (e.g. from CGE editor “Help → System Information” button “Save To File”). And exact Delphi version, in case it matters (though I did test examples/delphi/... in various Delphi 10, 11, and 12 versions).

If examples/delphi/vcl is not flashing – then it’s a question what is the client application doing non-standard. I recall our VCL TCastleControl required actually a fix to WM_ERASEBKGND to prevent it blinking (see procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND; in src/delphi/vcl.castlecontrol.pas). Ideas:

  • Could something in client application “cancel out” this?
  • Does the client application handle any WinAPI message directly, WM_ERASEBKGND or not?
  • What happens if you change the parent of TCastleControl, to be directly child of form?
  • What happens if you change the controls underneath TCastleControl, maybe some control behind TCastleControl is redrawing and this forces TCastleControl flashing – this would mean that TCastleControl should be a direct child of form, in case of VCL.

In his FormCreate is DoubleBuffered := True;. Setting that to false and the flashing stops.
DoubleBuffered should be unnecessary with CGE so I will remove that.